Spaces:
Sleeping
Sleeping
woletee
commited on
Commit
·
b091322
1
Parent(s):
da4a91c
added for the test pairs as well
Browse files- app.py +19 -17
- templates/results.html +9 -11
app.py
CHANGED
@@ -38,13 +38,13 @@ def upload():
|
|
38 |
for sample in data.get("train", []):
|
39 |
input_grid = sample["input"]
|
40 |
output_grid = sample["output"]
|
41 |
-
|
42 |
concept_label, _ = run_inference(model, input_grid, output_grid)
|
43 |
predicted_HLCs.append(concept_label)
|
44 |
input_output_pairs.append((input_grid, output_grid))
|
45 |
|
46 |
predicted_HLCs = list(set(predicted_HLCs))
|
47 |
|
|
|
48 |
best_program, generations = genetic_programming(
|
49 |
input_output_pairs=input_output_pairs,
|
50 |
population_size=300,
|
@@ -55,30 +55,32 @@ def upload():
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
-
#
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
last_input = input_output_pairs[-1][0] if input_output_pairs else []
|
66 |
-
last_ground_truth = input_output_pairs[-1][1] if input_output_pairs else []
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
except Exception as e:
|
71 |
-
print("Error during best_program evaluation:", e)
|
72 |
-
predicted_output = [["ERROR"]]
|
73 |
|
74 |
return render_template("results.html",
|
75 |
hlcs=predicted_HLCs,
|
76 |
input_output_pairs=input_output_pairs,
|
77 |
-
test_pairs=test_pairs,
|
78 |
best_program=str(best_program),
|
79 |
-
|
80 |
-
|
81 |
-
predicted_output=predicted_output)
|
82 |
|
83 |
if __name__ == '__main__':
|
84 |
app.run(host="0.0.0.0", port=7860)
|
|
|
38 |
for sample in data.get("train", []):
|
39 |
input_grid = sample["input"]
|
40 |
output_grid = sample["output"]
|
|
|
41 |
concept_label, _ = run_inference(model, input_grid, output_grid)
|
42 |
predicted_HLCs.append(concept_label)
|
43 |
input_output_pairs.append((input_grid, output_grid))
|
44 |
|
45 |
predicted_HLCs = list(set(predicted_HLCs))
|
46 |
|
47 |
+
# Run Genetic Programming
|
48 |
best_program, generations = genetic_programming(
|
49 |
input_output_pairs=input_output_pairs,
|
50 |
population_size=300,
|
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
+
# Prepare TEST PAIRS and predicted test outputs
|
59 |
+
test_pairs = []
|
60 |
+
predicted_test_outputs = []
|
61 |
+
|
62 |
+
for sample in data.get("test", []):
|
63 |
+
input_grid = tolist_safe(sample["input"])
|
64 |
+
output_grid = tolist_safe(sample["output"])
|
65 |
+
test_pairs.append((input_grid, output_grid))
|
66 |
|
67 |
+
try:
|
68 |
+
predicted = tolist_safe(best_program.evaluate(input_grid))
|
69 |
+
except Exception as e:
|
70 |
+
print("Error during prediction on test input:", e)
|
71 |
+
predicted = [["ERROR"]]
|
72 |
|
73 |
+
predicted_test_outputs.append(predicted)
|
|
|
|
|
74 |
|
75 |
+
# Clean train pairs for rendering
|
76 |
+
input_output_pairs = [(tolist_safe(i), tolist_safe(o)) for i, o in input_output_pairs]
|
|
|
|
|
|
|
77 |
|
78 |
return render_template("results.html",
|
79 |
hlcs=predicted_HLCs,
|
80 |
input_output_pairs=input_output_pairs,
|
|
|
81 |
best_program=str(best_program),
|
82 |
+
test_pairs=test_pairs,
|
83 |
+
predicted_test_outputs=predicted_test_outputs)
|
|
|
84 |
|
85 |
if __name__ == '__main__':
|
86 |
app.run(host="0.0.0.0", port=7860)
|
templates/results.html
CHANGED
@@ -68,10 +68,9 @@
|
|
68 |
|
69 |
<h1>Predicted High-Level Concepts</h1>
|
70 |
<h2>Input / Output Pairs with Concepts</h2>
|
71 |
-
|
72 |
<div id="pairs-container"></div>
|
73 |
|
74 |
-
<h2>Test
|
75 |
<div id="test-pairs-container"></div>
|
76 |
|
77 |
<h2>Best Program</h2>
|
@@ -81,6 +80,7 @@
|
|
81 |
const inputOutputPairs = {{ input_output_pairs | tojson | safe }};
|
82 |
const hlcs = {{ hlcs | tojson | safe }};
|
83 |
const testPairs = {{ test_pairs | tojson | safe }};
|
|
|
84 |
|
85 |
const colorMap = {
|
86 |
0: "#000000", 1: "#0074D9", 2: "#FF4136", 3: "#2ECC40",
|
@@ -103,7 +103,6 @@
|
|
103 |
}
|
104 |
|
105 |
const pairsContainer = document.getElementById("pairs-container");
|
106 |
-
|
107 |
inputOutputPairs.forEach((pair, index) => {
|
108 |
const container = document.createElement("div");
|
109 |
container.className = "grid-container";
|
@@ -152,17 +151,16 @@
|
|
152 |
drawGrid(inputGridBox, pair[0]);
|
153 |
|
154 |
const outputDiv = document.createElement("div");
|
155 |
-
outputDiv.innerHTML = `<div class="grid-title">
|
156 |
const outputGridBox = document.createElement("div");
|
157 |
outputGridBox.className = "grid-box";
|
158 |
outputDiv.appendChild(outputGridBox);
|
159 |
drawGrid(outputGridBox, pair[1]);
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
|
|
166 |
|
167 |
-
</body>
|
168 |
-
</html>
|
|
|
68 |
|
69 |
<h1>Predicted High-Level Concepts</h1>
|
70 |
<h2>Input / Output Pairs with Concepts</h2>
|
|
|
71 |
<div id="pairs-container"></div>
|
72 |
|
73 |
+
<h2>Test Set Evaluation</h2>
|
74 |
<div id="test-pairs-container"></div>
|
75 |
|
76 |
<h2>Best Program</h2>
|
|
|
80 |
const inputOutputPairs = {{ input_output_pairs | tojson | safe }};
|
81 |
const hlcs = {{ hlcs | tojson | safe }};
|
82 |
const testPairs = {{ test_pairs | tojson | safe }};
|
83 |
+
const predictedTestOutputs = {{ predicted_test_outputs | tojson | safe }};
|
84 |
|
85 |
const colorMap = {
|
86 |
0: "#000000", 1: "#0074D9", 2: "#FF4136", 3: "#2ECC40",
|
|
|
103 |
}
|
104 |
|
105 |
const pairsContainer = document.getElementById("pairs-container");
|
|
|
106 |
inputOutputPairs.forEach((pair, index) => {
|
107 |
const container = document.createElement("div");
|
108 |
container.className = "grid-container";
|
|
|
151 |
drawGrid(inputGridBox, pair[0]);
|
152 |
|
153 |
const outputDiv = document.createElement("div");
|
154 |
+
outputDiv.innerHTML = `<div class="grid-title">Ground Truth Output Grid</div>`;
|
155 |
const outputGridBox = document.createElement("div");
|
156 |
outputGridBox.className = "grid-box";
|
157 |
outputDiv.appendChild(outputGridBox);
|
158 |
drawGrid(outputGridBox, pair[1]);
|
159 |
|
160 |
+
const predDiv = document.createElement("div");
|
161 |
+
predDiv.innerHTML = `<div class="grid-title">Predicted Output by Program</div>`;
|
162 |
+
const predGridBox = document.createElement("div");
|
163 |
+
predGridBox.className = "grid-box";
|
164 |
+
predDiv.appendChild(predGridBox);
|
165 |
+
drawGrid(predGridBox, predictedTestOutputs[index]);
|
166 |
|
|
|
|