Switched to Flask app
Browse files- README.md +1 -1
- app.py +34 -61
- static/styles.css +0 -0
- templates/index.html +15 -0
- templates/results.html +19 -0
README.md
CHANGED
|
@@ -3,7 +3,7 @@ title: Conceptt
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: red
|
| 6 |
-
sdk:
|
| 7 |
sdk_version: 1.43.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
sdk_version: 1.43.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
app.py
CHANGED
|
@@ -1,82 +1,55 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import json
|
| 3 |
from Vit_concept import run_inference, model
|
| 4 |
from GP import genetic_programming
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
input_output_pairs = []
|
| 15 |
predicted_HLCs = []
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
for sample in data.get("train", []): # or 'test'
|
| 20 |
input_grid = sample["input"]
|
| 21 |
output_grid = sample["output"]
|
| 22 |
|
| 23 |
-
st.write("#### Input Grid:")
|
| 24 |
-
st.text(input_grid)
|
| 25 |
-
st.write("#### Output Grid:")
|
| 26 |
-
st.text(output_grid)
|
| 27 |
-
|
| 28 |
concept_label, _ = run_inference(model, input_grid, output_grid)
|
| 29 |
-
st.write(f" Predicted Concept: `{concept_label}`")
|
| 30 |
-
|
| 31 |
predicted_HLCs.append(concept_label)
|
| 32 |
input_output_pairs.append((input_grid, output_grid))
|
| 33 |
|
| 34 |
predicted_HLCs = list(set(predicted_HLCs))
|
| 35 |
-
st.write("### Predicted High-Level Concepts:", predicted_HLCs)
|
| 36 |
-
|
| 37 |
-
if st.button("Run Genetic Programming"):
|
| 38 |
-
st.write("Running Genetic Programming... (this may take a few minutes)")
|
| 39 |
-
best_program, generations = genetic_programming(
|
| 40 |
-
input_output_pairs=input_output_pairs,
|
| 41 |
-
population_size=300,
|
| 42 |
-
generations=500,
|
| 43 |
-
mutation_rate=0.2,
|
| 44 |
-
crossover_rate=0.7,
|
| 45 |
-
max_depth=3,
|
| 46 |
-
predicted_HLCs=predicted_HLCs
|
| 47 |
-
)
|
| 48 |
-
st.success(" GP Completed!")
|
| 49 |
-
st.write("### Best Program Found:")
|
| 50 |
-
st.code(str(best_program))
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
|
|
|
| 82 |
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template, redirect, url_for
|
| 2 |
+
import os
|
| 3 |
import json
|
| 4 |
from Vit_concept import run_inference, model
|
| 5 |
from GP import genetic_programming
|
| 6 |
|
| 7 |
+
app = Flask(__name__)
|
| 8 |
+
UPLOAD_FOLDER = 'uploads'
|
| 9 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 10 |
|
| 11 |
+
@app.route('/')
|
| 12 |
+
def index():
|
| 13 |
+
return render_template('index.html')
|
| 14 |
|
| 15 |
+
@app.route('/upload', methods=['POST'])
|
| 16 |
+
def upload():
|
| 17 |
+
if 'file' not in request.files:
|
| 18 |
+
return "No file part"
|
| 19 |
+
file = request.files['file']
|
| 20 |
+
if file.filename == '':
|
| 21 |
+
return "No selected file"
|
| 22 |
+
|
| 23 |
+
filepath = os.path.join(UPLOAD_FOLDER, file.filename)
|
| 24 |
+
file.save(filepath)
|
| 25 |
+
|
| 26 |
+
with open(filepath, 'r') as f:
|
| 27 |
+
data = json.load(f)
|
| 28 |
|
| 29 |
input_output_pairs = []
|
| 30 |
predicted_HLCs = []
|
| 31 |
|
| 32 |
+
for sample in data.get("train", []):
|
|
|
|
|
|
|
| 33 |
input_grid = sample["input"]
|
| 34 |
output_grid = sample["output"]
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
concept_label, _ = run_inference(model, input_grid, output_grid)
|
|
|
|
|
|
|
| 37 |
predicted_HLCs.append(concept_label)
|
| 38 |
input_output_pairs.append((input_grid, output_grid))
|
| 39 |
|
| 40 |
predicted_HLCs = list(set(predicted_HLCs))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
best_program, generations = genetic_programming(
|
| 43 |
+
input_output_pairs=input_output_pairs,
|
| 44 |
+
population_size=300,
|
| 45 |
+
generations=500,
|
| 46 |
+
mutation_rate=0.2,
|
| 47 |
+
crossover_rate=0.7,
|
| 48 |
+
max_depth=3,
|
| 49 |
+
predicted_HLCs=predicted_HLCs
|
| 50 |
+
)
|
| 51 |
|
| 52 |
+
return render_template("results.html", hlcs=predicted_HLCs, program=str(best_program))
|
| 53 |
|
| 54 |
+
if __name__ == '__main__':
|
| 55 |
+
app.run(host="0.0.0.0", port=7860)
|
static/styles.css
ADDED
|
File without changes
|
templates/index.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>ARC Task Solver</title>
|
| 6 |
+
<link rel="stylesheet" href="/static/styles.css">
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h1>Upload ARC Task File</h1>
|
| 10 |
+
<form action="/upload" method="post" enctype="multipart/form-data">
|
| 11 |
+
<input type="file" name="file" accept=".json" required>
|
| 12 |
+
<button type="submit">Upload & Solve</button>
|
| 13 |
+
</form>
|
| 14 |
+
</body>
|
| 15 |
+
</html>
|
templates/results.html
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Results</title>
|
| 6 |
+
<link rel="stylesheet" href="/static/styles.css">
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h1>Predicted Concepts</h1>
|
| 10 |
+
<ul>
|
| 11 |
+
{% for hlc in hlcs %}
|
| 12 |
+
<li>{{ hlc }}</li>
|
| 13 |
+
{% endfor %}
|
| 14 |
+
</ul>
|
| 15 |
+
|
| 16 |
+
<h2>Best Genetic Program</h2>
|
| 17 |
+
<pre>{{ program }}</pre>
|
| 18 |
+
</body>
|
| 19 |
+
</html>
|