Spaces:
Sleeping
Sleeping
woletee
commited on
Commit
·
6fb64b4
1
Parent(s):
0c77885
this is the alst updated code for both the index.html and for both the app.py code
Browse files- app.py +20 -8
- templates/results.html +31 -17
app.py
CHANGED
@@ -41,7 +41,7 @@ def upload():
|
|
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 |
|
@@ -55,13 +55,7 @@ def upload():
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
-
#
|
59 |
-
input_output_pairs = [(tolist_safe(i), tolist_safe(o)) for i, o in input_output_pairs]
|
60 |
-
|
61 |
-
# Prepare test pairs as well
|
62 |
-
test_pairs = [(tolist_safe(sample["input"]), tolist_safe(sample["output"])) for sample in data.get("test", [])]
|
63 |
-
|
64 |
-
# Prepare final program evaluation display
|
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 |
|
@@ -71,10 +65,28 @@ def upload():
|
|
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 |
last_input=last_input,
|
80 |
last_ground_truth=last_ground_truth,
|
|
|
41 |
|
42 |
concept_label, _ = run_inference(model, input_grid, output_grid)
|
43 |
predicted_HLCs.append(concept_label)
|
44 |
+
input_output_pairs.append((tolist_safe(input_grid), tolist_safe(output_grid)))
|
45 |
|
46 |
predicted_HLCs = list(set(predicted_HLCs))
|
47 |
|
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
+
# Last grid for optional evaluation
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
last_input = input_output_pairs[-1][0] if input_output_pairs else []
|
60 |
last_ground_truth = input_output_pairs[-1][1] if input_output_pairs else []
|
61 |
|
|
|
65 |
print("Error during best_program evaluation:", e)
|
66 |
predicted_output = [["ERROR"]]
|
67 |
|
68 |
+
# Evaluate program on test pairs
|
69 |
+
test_pairs = []
|
70 |
+
predicted_test_outputs = []
|
71 |
+
|
72 |
+
for sample in data.get("test", []):
|
73 |
+
test_input = tolist_safe(sample["input"])
|
74 |
+
test_output = tolist_safe(sample["output"])
|
75 |
+
test_pairs.append((test_input, test_output))
|
76 |
+
|
77 |
+
try:
|
78 |
+
predicted = tolist_safe(best_program.evaluate(test_input))
|
79 |
+
except Exception as e:
|
80 |
+
print("Error evaluating test input:", e)
|
81 |
+
predicted = [["ERROR"]]
|
82 |
+
|
83 |
+
predicted_test_outputs.append(predicted)
|
84 |
+
|
85 |
return render_template("results.html",
|
86 |
hlcs=predicted_HLCs,
|
87 |
input_output_pairs=input_output_pairs,
|
88 |
test_pairs=test_pairs,
|
89 |
+
predicted_test_outputs=predicted_test_outputs,
|
90 |
best_program=str(best_program),
|
91 |
last_input=last_input,
|
92 |
last_ground_truth=last_ground_truth,
|
templates/results.html
CHANGED
@@ -67,11 +67,16 @@
|
|
67 |
<body>
|
68 |
|
69 |
<h1>Predicted High-Level Concepts</h1>
|
70 |
-
<
|
|
|
|
|
|
|
|
|
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 +86,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",
|
@@ -92,6 +98,7 @@
|
|
92 |
if (!Array.isArray(gridData) || !gridData.length || !Array.isArray(gridData[0])) return;
|
93 |
container.style.gridTemplateRows = `repeat(${gridData.length}, 25px)`;
|
94 |
container.style.gridTemplateColumns = `repeat(${gridData[0].length}, 25px)`;
|
|
|
95 |
gridData.forEach(row => {
|
96 |
row.forEach(cell => {
|
97 |
const div = document.createElement("div");
|
@@ -102,6 +109,7 @@
|
|
102 |
});
|
103 |
}
|
104 |
|
|
|
105 |
const pairsContainer = document.getElementById("pairs-container");
|
106 |
|
107 |
inputOutputPairs.forEach((pair, index) => {
|
@@ -124,14 +132,10 @@
|
|
124 |
|
125 |
const conceptDiv = document.createElement("div");
|
126 |
conceptDiv.className = "concept-box";
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
conceptText.className = "concept-text";
|
132 |
-
conceptText.innerText = hlcs[index] || "N/A";
|
133 |
-
conceptDiv.appendChild(conceptTitle);
|
134 |
-
conceptDiv.appendChild(conceptText);
|
135 |
|
136 |
container.appendChild(inputDiv);
|
137 |
container.appendChild(outputDiv);
|
@@ -139,7 +143,9 @@
|
|
139 |
pairsContainer.appendChild(container);
|
140 |
});
|
141 |
|
|
|
142 |
const testContainer = document.getElementById("test-pairs-container");
|
|
|
143 |
testPairs.forEach((pair, index) => {
|
144 |
const container = document.createElement("div");
|
145 |
container.className = "grid-container";
|
@@ -151,15 +157,23 @@
|
|
151 |
inputDiv.appendChild(inputGridBox);
|
152 |
drawGrid(inputGridBox, pair[0]);
|
153 |
|
154 |
-
const
|
155 |
-
|
156 |
-
const
|
157 |
-
|
158 |
-
|
159 |
-
drawGrid(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
container.appendChild(inputDiv);
|
162 |
-
container.appendChild(
|
|
|
163 |
testContainer.appendChild(container);
|
164 |
});
|
165 |
</script>
|
|
|
67 |
<body>
|
68 |
|
69 |
<h1>Predicted High-Level Concepts</h1>
|
70 |
+
<ul>
|
71 |
+
{% for concept in hlcs %}
|
72 |
+
<li>{{ concept }}</li>
|
73 |
+
{% endfor %}
|
74 |
+
</ul>
|
75 |
|
76 |
+
<h2>Training Input / Output Pairs with Concepts</h2>
|
77 |
<div id="pairs-container"></div>
|
78 |
|
79 |
+
<h2>Test Input / Ground Truth / Predicted Outputs</h2>
|
80 |
<div id="test-pairs-container"></div>
|
81 |
|
82 |
<h2>Best Program</h2>
|
|
|
86 |
const inputOutputPairs = {{ input_output_pairs | tojson | safe }};
|
87 |
const hlcs = {{ hlcs | tojson | safe }};
|
88 |
const testPairs = {{ test_pairs | tojson | safe }};
|
89 |
+
const predictedTestOutputs = {{ predicted_test_outputs | tojson | safe }};
|
90 |
|
91 |
const colorMap = {
|
92 |
0: "#000000", 1: "#0074D9", 2: "#FF4136", 3: "#2ECC40",
|
|
|
98 |
if (!Array.isArray(gridData) || !gridData.length || !Array.isArray(gridData[0])) return;
|
99 |
container.style.gridTemplateRows = `repeat(${gridData.length}, 25px)`;
|
100 |
container.style.gridTemplateColumns = `repeat(${gridData[0].length}, 25px)`;
|
101 |
+
container.innerHTML = '';
|
102 |
gridData.forEach(row => {
|
103 |
row.forEach(cell => {
|
104 |
const div = document.createElement("div");
|
|
|
109 |
});
|
110 |
}
|
111 |
|
112 |
+
// TRAINING PAIRS
|
113 |
const pairsContainer = document.getElementById("pairs-container");
|
114 |
|
115 |
inputOutputPairs.forEach((pair, index) => {
|
|
|
132 |
|
133 |
const conceptDiv = document.createElement("div");
|
134 |
conceptDiv.className = "concept-box";
|
135 |
+
conceptDiv.innerHTML = `
|
136 |
+
<div class="concept-title">Concept</div>
|
137 |
+
<div class="concept-text">${hlcs[index] || 'N/A'}</div>
|
138 |
+
`;
|
|
|
|
|
|
|
|
|
139 |
|
140 |
container.appendChild(inputDiv);
|
141 |
container.appendChild(outputDiv);
|
|
|
143 |
pairsContainer.appendChild(container);
|
144 |
});
|
145 |
|
146 |
+
// TEST PAIRS AND PREDICTIONS
|
147 |
const testContainer = document.getElementById("test-pairs-container");
|
148 |
+
|
149 |
testPairs.forEach((pair, index) => {
|
150 |
const container = document.createElement("div");
|
151 |
container.className = "grid-container";
|
|
|
157 |
inputDiv.appendChild(inputGridBox);
|
158 |
drawGrid(inputGridBox, pair[0]);
|
159 |
|
160 |
+
const gtDiv = document.createElement("div");
|
161 |
+
gtDiv.innerHTML = `<div class="grid-title">Ground Truth Output</div>`;
|
162 |
+
const gtGridBox = document.createElement("div");
|
163 |
+
gtGridBox.className = "grid-box";
|
164 |
+
gtDiv.appendChild(gtGridBox);
|
165 |
+
drawGrid(gtGridBox, pair[1]);
|
166 |
+
|
167 |
+
const predDiv = document.createElement("div");
|
168 |
+
predDiv.innerHTML = `<div class="grid-title">Predicted Output</div>`;
|
169 |
+
const predGridBox = document.createElement("div");
|
170 |
+
predGridBox.className = "grid-box";
|
171 |
+
predDiv.appendChild(predGridBox);
|
172 |
+
drawGrid(predGridBox, predictedTestOutputs[index]);
|
173 |
|
174 |
container.appendChild(inputDiv);
|
175 |
+
container.appendChild(gtDiv);
|
176 |
+
container.appendChild(predDiv);
|
177 |
testContainer.appendChild(container);
|
178 |
});
|
179 |
</script>
|