Spaces:
Sleeping
Sleeping
woletee
commited on
Commit
·
007874f
1
Parent(s):
b091322
this is about returning to the orginal one
Browse files- app.py +13 -19
- templates/results.html +15 -48
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 |
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,32 +55,26 @@ def upload():
|
|
55 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
-
# Prepare
|
59 |
-
|
60 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
#
|
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 |
-
|
83 |
-
|
|
|
84 |
|
85 |
if __name__ == '__main__':
|
86 |
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 |
+
|
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 |
predicted_HLCs=predicted_HLCs
|
56 |
)
|
57 |
|
58 |
+
# Prepare final grids for evaluation section
|
59 |
+
last_input = tolist_safe(input_output_pairs[-1][0])
|
60 |
+
last_ground_truth = tolist_safe(input_output_pairs[-1][1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
try:
|
63 |
+
predicted_output = tolist_safe(best_program.evaluate(last_input))
|
64 |
+
except Exception as e:
|
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,
|
77 |
+
predicted_output=predicted_output)
|
78 |
|
79 |
if __name__ == '__main__':
|
80 |
app.run(host="0.0.0.0", port=7860)
|
templates/results.html
CHANGED
@@ -51,45 +51,29 @@
|
|
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>
|
68 |
|
69 |
<h1>Predicted High-Level Concepts</h1>
|
70 |
<h2>Input / Output Pairs with Concepts</h2>
|
71 |
-
<div id="pairs-container"></div>
|
72 |
|
73 |
-
<
|
74 |
-
<div id="test-pairs-container"></div>
|
75 |
|
76 |
<h2>Best Program</h2>
|
77 |
<pre>{{ best_program }}</pre>
|
78 |
|
79 |
<script>
|
80 |
-
const inputOutputPairs = {{ input_output_pairs | tojson
|
81 |
-
const hlcs = {{ hlcs | tojson
|
82 |
-
const testPairs = {{ test_pairs | tojson | safe }};
|
83 |
-
const predictedTestOutputs = {{ predicted_test_outputs | tojson | safe }};
|
84 |
|
85 |
const colorMap = {
|
86 |
-
0: "#
|
87 |
-
4: "#FFDC00", 5: "#
|
88 |
-
8: "#
|
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 => {
|
@@ -103,10 +87,12 @@
|
|
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";
|
109 |
|
|
|
110 |
const inputDiv = document.createElement("div");
|
111 |
inputDiv.innerHTML = `<div class="grid-title">Input Grid</div>`;
|
112 |
const inputGridBox = document.createElement("div");
|
@@ -114,6 +100,7 @@
|
|
114 |
inputDiv.appendChild(inputGridBox);
|
115 |
drawGrid(inputGridBox, pair[0]);
|
116 |
|
|
|
117 |
const outputDiv = document.createElement("div");
|
118 |
outputDiv.innerHTML = `<div class="grid-title">Output Grid</div>`;
|
119 |
const outputGridBox = document.createElement("div");
|
@@ -121,6 +108,7 @@
|
|
121 |
outputDiv.appendChild(outputGridBox);
|
122 |
drawGrid(outputGridBox, pair[1]);
|
123 |
|
|
|
124 |
const conceptDiv = document.createElement("div");
|
125 |
conceptDiv.className = "concept-box";
|
126 |
const conceptTitle = document.createElement("div");
|
@@ -129,38 +117,17 @@
|
|
129 |
const conceptText = document.createElement("div");
|
130 |
conceptText.className = "concept-text";
|
131 |
conceptText.innerText = hlcs[index] || "N/A";
|
|
|
132 |
conceptDiv.appendChild(conceptTitle);
|
133 |
conceptDiv.appendChild(conceptText);
|
134 |
|
|
|
135 |
container.appendChild(inputDiv);
|
136 |
container.appendChild(outputDiv);
|
137 |
container.appendChild(conceptDiv);
|
138 |
pairsContainer.appendChild(container);
|
139 |
});
|
|
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
const container = document.createElement("div");
|
144 |
-
container.className = "grid-container";
|
145 |
-
|
146 |
-
const inputDiv = document.createElement("div");
|
147 |
-
inputDiv.innerHTML = `<div class="grid-title">Test Input Grid</div>`;
|
148 |
-
const inputGridBox = document.createElement("div");
|
149 |
-
inputGridBox.className = "grid-box";
|
150 |
-
inputDiv.appendChild(inputGridBox);
|
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 |
-
|
|
|
51 |
border-radius: 8px;
|
52 |
background-color: #f4f4f4;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
</style>
|
55 |
</head>
|
56 |
<body>
|
57 |
|
58 |
<h1>Predicted High-Level Concepts</h1>
|
59 |
<h2>Input / Output Pairs with Concepts</h2>
|
|
|
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: "#FFFFFF", 1: "#0074D9", 2: "#FF4136", 3: "#2ECC40",
|
72 |
+
4: "#FFDC00", 5: "#B10DC9", 6: "#FF851B", 7: "#7FDBFF",
|
73 |
+
8: "#F012BE", 9: "#111111"
|
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 => {
|
|
|
87 |
}
|
88 |
|
89 |
const pairsContainer = document.getElementById("pairs-container");
|
90 |
+
|
91 |
inputOutputPairs.forEach((pair, index) => {
|
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 |
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 |
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 |
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>
|
133 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|