Spaces:
Sleeping
Sleeping
woletee
commited on
Commit
·
0c77885
1
Parent(s):
007874f
this is retunring to the orignal
Browse files- app.py +10 -6
- templates/results.html +45 -10
app.py
CHANGED
@@ -55,9 +55,15 @@ def upload():
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
-
#
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
try:
|
63 |
predicted_output = tolist_safe(best_program.evaluate(last_input))
|
@@ -65,12 +71,10 @@ def upload():
|
|
65 |
print("Error during best_program evaluation:", e)
|
66 |
predicted_output = [["ERROR"]]
|
67 |
|
68 |
-
# Convert all pairs to lists (in case of NumPy values)
|
69 |
-
input_output_pairs = [(tolist_safe(i), tolist_safe(o)) for i, o in input_output_pairs]
|
70 |
-
|
71 |
return render_template("results.html",
|
72 |
hlcs=predicted_HLCs,
|
73 |
input_output_pairs=input_output_pairs,
|
|
|
74 |
best_program=str(best_program),
|
75 |
last_input=last_input,
|
76 |
last_ground_truth=last_ground_truth,
|
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
+
# Convert train pairs to plain lists
|
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 |
|
68 |
try:
|
69 |
predicted_output = tolist_safe(best_program.evaluate(last_input))
|
|
|
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,
|
templates/results.html
CHANGED
@@ -51,6 +51,17 @@
|
|
51 |
border-radius: 8px;
|
52 |
background-color: #f4f4f4;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
</style>
|
55 |
</head>
|
56 |
<body>
|
@@ -60,20 +71,25 @@
|
|
60 |
|
61 |
<div id="pairs-container"></div>
|
62 |
|
|
|
|
|
|
|
63 |
<h2>Best Program</h2>
|
64 |
<pre>{{ best_program }}</pre>
|
65 |
|
66 |
<script>
|
67 |
-
const inputOutputPairs = {{ input_output_pairs | tojson }};
|
68 |
-
const hlcs = {{ hlcs | tojson }};
|
|
|
69 |
|
70 |
const colorMap = {
|
71 |
-
0: "#
|
72 |
-
4: "#FFDC00", 5: "#
|
73 |
-
8: "#
|
74 |
};
|
75 |
|
76 |
function drawGrid(container, gridData) {
|
|
|
77 |
container.style.gridTemplateRows = `repeat(${gridData.length}, 25px)`;
|
78 |
container.style.gridTemplateColumns = `repeat(${gridData[0].length}, 25px)`;
|
79 |
gridData.forEach(row => {
|
@@ -92,7 +108,6 @@
|
|
92 |
const container = document.createElement("div");
|
93 |
container.className = "grid-container";
|
94 |
|
95 |
-
// Input Grid
|
96 |
const inputDiv = document.createElement("div");
|
97 |
inputDiv.innerHTML = `<div class="grid-title">Input Grid</div>`;
|
98 |
const inputGridBox = document.createElement("div");
|
@@ -100,7 +115,6 @@
|
|
100 |
inputDiv.appendChild(inputGridBox);
|
101 |
drawGrid(inputGridBox, pair[0]);
|
102 |
|
103 |
-
// Output Grid
|
104 |
const outputDiv = document.createElement("div");
|
105 |
outputDiv.innerHTML = `<div class="grid-title">Output Grid</div>`;
|
106 |
const outputGridBox = document.createElement("div");
|
@@ -108,7 +122,6 @@
|
|
108 |
outputDiv.appendChild(outputGridBox);
|
109 |
drawGrid(outputGridBox, pair[1]);
|
110 |
|
111 |
-
// Concept Box
|
112 |
const conceptDiv = document.createElement("div");
|
113 |
conceptDiv.className = "concept-box";
|
114 |
const conceptTitle = document.createElement("div");
|
@@ -117,16 +130,38 @@
|
|
117 |
const conceptText = document.createElement("div");
|
118 |
conceptText.className = "concept-text";
|
119 |
conceptText.innerText = hlcs[index] || "N/A";
|
120 |
-
|
121 |
conceptDiv.appendChild(conceptTitle);
|
122 |
conceptDiv.appendChild(conceptText);
|
123 |
|
124 |
-
// Combine everything into one row
|
125 |
container.appendChild(inputDiv);
|
126 |
container.appendChild(outputDiv);
|
127 |
container.appendChild(conceptDiv);
|
128 |
pairsContainer.appendChild(container);
|
129 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
</script>
|
131 |
|
132 |
</body>
|
|
|
51 |
border-radius: 8px;
|
52 |
background-color: #f4f4f4;
|
53 |
}
|
54 |
+
pre {
|
55 |
+
background-color: #f5f5f5;
|
56 |
+
padding: 15px;
|
57 |
+
font-family: Consolas, monospace;
|
58 |
+
font-size: 14px;
|
59 |
+
border-radius: 8px;
|
60 |
+
max-width: 900px;
|
61 |
+
margin: auto;
|
62 |
+
white-space: pre-wrap;
|
63 |
+
border: 1px solid #ddd;
|
64 |
+
}
|
65 |
</style>
|
66 |
</head>
|
67 |
<body>
|
|
|
71 |
|
72 |
<div id="pairs-container"></div>
|
73 |
|
74 |
+
<h2>Test Pairs</h2>
|
75 |
+
<div id="test-pairs-container"></div>
|
76 |
+
|
77 |
<h2>Best Program</h2>
|
78 |
<pre>{{ best_program }}</pre>
|
79 |
|
80 |
<script>
|
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",
|
87 |
+
4: "#FFDC00", 5: "#AAAAAA", 6: "#F012BE", 7: "#FF851B",
|
88 |
+
8: "#7FDBFF", 9: "#870C25"
|
89 |
};
|
90 |
|
91 |
function drawGrid(container, gridData) {
|
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 => {
|
|
|
108 |
const container = document.createElement("div");
|
109 |
container.className = "grid-container";
|
110 |
|
|
|
111 |
const inputDiv = document.createElement("div");
|
112 |
inputDiv.innerHTML = `<div class="grid-title">Input Grid</div>`;
|
113 |
const inputGridBox = document.createElement("div");
|
|
|
115 |
inputDiv.appendChild(inputGridBox);
|
116 |
drawGrid(inputGridBox, pair[0]);
|
117 |
|
|
|
118 |
const outputDiv = document.createElement("div");
|
119 |
outputDiv.innerHTML = `<div class="grid-title">Output Grid</div>`;
|
120 |
const outputGridBox = document.createElement("div");
|
|
|
122 |
outputDiv.appendChild(outputGridBox);
|
123 |
drawGrid(outputGridBox, pair[1]);
|
124 |
|
|
|
125 |
const conceptDiv = document.createElement("div");
|
126 |
conceptDiv.className = "concept-box";
|
127 |
const conceptTitle = document.createElement("div");
|
|
|
130 |
const conceptText = document.createElement("div");
|
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);
|
138 |
container.appendChild(conceptDiv);
|
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";
|
146 |
+
|
147 |
+
const inputDiv = document.createElement("div");
|
148 |
+
inputDiv.innerHTML = `<div class="grid-title">Test Input Grid</div>`;
|
149 |
+
const inputGridBox = document.createElement("div");
|
150 |
+
inputGridBox.className = "grid-box";
|
151 |
+
inputDiv.appendChild(inputGridBox);
|
152 |
+
drawGrid(inputGridBox, pair[0]);
|
153 |
+
|
154 |
+
const outputDiv = document.createElement("div");
|
155 |
+
outputDiv.innerHTML = `<div class="grid-title">Test Ground Truth Output Grid</div>`;
|
156 |
+
const outputGridBox = document.createElement("div");
|
157 |
+
outputGridBox.className = "grid-box";
|
158 |
+
outputDiv.appendChild(outputGridBox);
|
159 |
+
drawGrid(outputGridBox, pair[1]);
|
160 |
+
|
161 |
+
container.appendChild(inputDiv);
|
162 |
+
container.appendChild(outputDiv);
|
163 |
+
testContainer.appendChild(container);
|
164 |
+
});
|
165 |
</script>
|
166 |
|
167 |
</body>
|