Spaces:
Sleeping
Sleeping
woletee
commited on
Commit
·
2f1b584
1
Parent(s):
0ecdc68
I am not sure if this change could be applicable or not
Browse files- GP.py +2 -20
- Vit_concept.py +1 -12
- __pycache__/GP.cpython-38.pyc +0 -0
- __pycache__/Nods.cpython-38.pyc +0 -0
- __pycache__/Vit_concept.cpython-38.pyc +0 -0
- __pycache__/custom_t5_vit.cpython-38.pyc +0 -0
- __pycache__/dsl.cpython-38.pyc +0 -0
- __pycache__/task_loader.cpython-38.pyc +0 -0
- app.py +7 -13
- templates/index.html +28 -5
- templates/results.html +1 -1
- uploads/AboveBelow3 (6).json +1 -0
GP.py
CHANGED
@@ -350,29 +350,11 @@ def genetic_programming(input_output_pairs, population_size, generations, mutati
|
|
350 |
if __name__ == "__main__":
|
351 |
if __name__ == "__main__":
|
352 |
input_output_pairs = [
|
353 |
-
|
354 |
-
[[0,0,0,0,0,0,0,0],
|
355 |
-
[0,3,3,3,0,0,0,0],
|
356 |
-
[0,0,0,0,0,0,0,0],
|
357 |
-
[0,4,4,4,0,0,0,0],
|
358 |
-
[0,4,4,4,0,0,0,0],
|
359 |
-
[0,4,4,4,0,0,0,0],
|
360 |
-
[0,0,0,0,0,3,3,3],
|
361 |
-
[0,0,3,3,3,0,0,0]],
|
362 |
-
|
363 |
-
[[0,0,0,0,0,0,0,0],
|
364 |
-
[0,0,0,0,0,0,0,0],
|
365 |
-
[0,3,3,3,0,0,0,0],
|
366 |
-
[0,4,4,4,0,0,0,0],
|
367 |
-
[0,4,4,4,0,0,0,0],
|
368 |
-
[0,4,4,4,0,0,0,0],
|
369 |
-
[0,0,0,0,0,3,3,3],
|
370 |
-
[0,0,3,3,3,0,0,0]]
|
371 |
-
)
|
372 |
]
|
373 |
|
374 |
|
375 |
-
predicted_HLCs = [
|
376 |
|
377 |
|
378 |
best_program, generations = genetic_programming(
|
|
|
350 |
if __name__ == "__main__":
|
351 |
if __name__ == "__main__":
|
352 |
input_output_pairs = [
|
353 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
]
|
355 |
|
356 |
|
357 |
+
predicted_HLCs = []
|
358 |
|
359 |
|
360 |
best_program, generations = genetic_programming(
|
Vit_concept.py
CHANGED
@@ -83,12 +83,8 @@ def preprocess_for_inference(input_grid, output_grid):
|
|
83 |
input_tokens = "<s> Input Grid: " + reformat_arc_tokens(input_grid) + " </s>"
|
84 |
output_tokens = " Output Grid: " + reformat_arc_tokens(output_grid) + " </s>"
|
85 |
return input_tokens + output_tokens
|
86 |
-
# Concept Label Mapping
|
87 |
CONCEPT_LABELS = {'Above_below': 0, 'Below_row_line': 1, 'Center': 2, 'Copy': 3, 'Horizontal_vertical': 4, 'Inside_outside': 5, 'Remove_below_horizontal_line': 6}
|
88 |
-
|
89 |
CONCEPT_LABELS_INV = {v: k for k, v in CONCEPT_LABELS.items()}
|
90 |
-
|
91 |
-
# Map ViT Concept to GP Function
|
92 |
CONCEPT_TO_FUNCTION_MAP = {
|
93 |
'Center': 'find_center_pixel',
|
94 |
'Copy': 'identity',
|
@@ -114,14 +110,9 @@ def run_inference(model, input_grid, output_grid):
|
|
114 |
|
115 |
return concept_label, mapped_function
|
116 |
if __name__ == "__main__":
|
117 |
-
# Path to your JSON file
|
118 |
JSON_DATA_PATH = r"C:\Users\gebre\OneDrive - GIST\문서\KakaoTalk Downloads\GPARC_concept_with_vit\GPARC\SRC\data\AboveBelow3.json"
|
119 |
-
|
120 |
-
# Load JSON data
|
121 |
with open(JSON_DATA_PATH, "r") as f:
|
122 |
data = json.load(f)
|
123 |
-
|
124 |
-
# Loop through both train and test sets
|
125 |
results = []
|
126 |
|
127 |
for split_name in ["train", "test"]:
|
@@ -136,14 +127,12 @@ if __name__ == "__main__":
|
|
136 |
"input": input_grid,
|
137 |
"output": output_grid,
|
138 |
"predicted_label": predicted_label,
|
139 |
-
"mapped_function": str(mapped_function)
|
140 |
})
|
141 |
results.append({
|
142 |
"split": split_name,
|
143 |
"predictions": split_results
|
144 |
})
|
145 |
-
|
146 |
-
# Optionally: save the result to a JSON file
|
147 |
with open("inference_results.json", "w") as f:
|
148 |
json.dump(results, f, indent=2)
|
149 |
|
|
|
83 |
input_tokens = "<s> Input Grid: " + reformat_arc_tokens(input_grid) + " </s>"
|
84 |
output_tokens = " Output Grid: " + reformat_arc_tokens(output_grid) + " </s>"
|
85 |
return input_tokens + output_tokens
|
|
|
86 |
CONCEPT_LABELS = {'Above_below': 0, 'Below_row_line': 1, 'Center': 2, 'Copy': 3, 'Horizontal_vertical': 4, 'Inside_outside': 5, 'Remove_below_horizontal_line': 6}
|
|
|
87 |
CONCEPT_LABELS_INV = {v: k for k, v in CONCEPT_LABELS.items()}
|
|
|
|
|
88 |
CONCEPT_TO_FUNCTION_MAP = {
|
89 |
'Center': 'find_center_pixel',
|
90 |
'Copy': 'identity',
|
|
|
110 |
|
111 |
return concept_label, mapped_function
|
112 |
if __name__ == "__main__":
|
|
|
113 |
JSON_DATA_PATH = r"C:\Users\gebre\OneDrive - GIST\문서\KakaoTalk Downloads\GPARC_concept_with_vit\GPARC\SRC\data\AboveBelow3.json"
|
|
|
|
|
114 |
with open(JSON_DATA_PATH, "r") as f:
|
115 |
data = json.load(f)
|
|
|
|
|
116 |
results = []
|
117 |
|
118 |
for split_name in ["train", "test"]:
|
|
|
127 |
"input": input_grid,
|
128 |
"output": output_grid,
|
129 |
"predicted_label": predicted_label,
|
130 |
+
"mapped_function": str(mapped_function)
|
131 |
})
|
132 |
results.append({
|
133 |
"split": split_name,
|
134 |
"predictions": split_results
|
135 |
})
|
|
|
|
|
136 |
with open("inference_results.json", "w") as f:
|
137 |
json.dump(results, f, indent=2)
|
138 |
|
__pycache__/GP.cpython-38.pyc
ADDED
Binary file (11.6 kB). View file
|
|
__pycache__/Nods.cpython-38.pyc
ADDED
Binary file (3.33 kB). View file
|
|
__pycache__/Vit_concept.cpython-38.pyc
ADDED
Binary file (6.25 kB). View file
|
|
__pycache__/custom_t5_vit.cpython-38.pyc
ADDED
Binary file (34 kB). View file
|
|
__pycache__/dsl.cpython-38.pyc
ADDED
Binary file (18.5 kB). View file
|
|
__pycache__/task_loader.cpython-38.pyc
ADDED
Binary file (958 Bytes). View file
|
|
app.py
CHANGED
@@ -16,19 +16,13 @@ def tolist_safe(obj):
|
|
16 |
def index():
|
17 |
return render_template('index.html')
|
18 |
|
19 |
-
@app.route('/
|
20 |
-
def
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return "
|
26 |
-
|
27 |
-
filepath = os.path.join(UPLOAD_FOLDER, file.filename)
|
28 |
-
file.save(filepath)
|
29 |
-
|
30 |
-
with open(filepath, 'r') as f:
|
31 |
-
data = json.load(f)
|
32 |
|
33 |
# Collect training data and predict HLCs
|
34 |
input_output_pairs = []
|
|
|
16 |
def index():
|
17 |
return render_template('index.html')
|
18 |
|
19 |
+
@app.route('/submit_json', methods=['POST'])
|
20 |
+
def submit_json():
|
21 |
+
try:
|
22 |
+
raw_json = request.form.get('json_input')
|
23 |
+
data = json.loads(raw_json)
|
24 |
+
except Exception as e:
|
25 |
+
return f"Invalid JSON input: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Collect training data and predict HLCs
|
28 |
input_output_pairs = []
|
templates/index.html
CHANGED
@@ -2,13 +2,36 @@
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
-
<title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
</head>
|
7 |
<body>
|
8 |
-
|
9 |
-
<
|
10 |
-
|
11 |
-
<
|
|
|
12 |
</form>
|
|
|
13 |
</body>
|
14 |
</html>
|
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
+
<title>Paste ARC Task JSON</title>
|
6 |
+
<style>
|
7 |
+
body {
|
8 |
+
font-family: Arial, sans-serif;
|
9 |
+
background-color: white;
|
10 |
+
padding: 30px;
|
11 |
+
text-align: center;
|
12 |
+
}
|
13 |
+
textarea {
|
14 |
+
width: 80%;
|
15 |
+
height: 300px;
|
16 |
+
padding: 10px;
|
17 |
+
font-family: monospace;
|
18 |
+
font-size: 14px;
|
19 |
+
margin-bottom: 20px;
|
20 |
+
}
|
21 |
+
button {
|
22 |
+
padding: 10px 20px;
|
23 |
+
font-size: 16px;
|
24 |
+
cursor: pointer;
|
25 |
+
}
|
26 |
+
</style>
|
27 |
</head>
|
28 |
<body>
|
29 |
+
|
30 |
+
<h1>Concept Guided GP</h1>
|
31 |
+
<form action="/submit_json" method="post">
|
32 |
+
<textarea name="json_input" placeholder="ARC task" required></textarea><br>
|
33 |
+
<button type="submit">What concept is in this task</button>
|
34 |
</form>
|
35 |
+
|
36 |
</body>
|
37 |
</html>
|
templates/results.html
CHANGED
@@ -64,7 +64,7 @@
|
|
64 |
</head>
|
65 |
<body>
|
66 |
|
67 |
-
<h1>Concept Guided
|
68 |
|
69 |
<h2>Step1: Training Pairs (left) with Concepts by recognition module (right most)</h2>
|
70 |
<div id="pairs-container"></div>
|
|
|
64 |
</head>
|
65 |
<body>
|
66 |
|
67 |
+
<h1>Concept Guided PS</h1>
|
68 |
|
69 |
<h2>Step1: Training Pairs (left) with Concepts by recognition module (right most)</h2>
|
70 |
<div id="pairs-container"></div>
|
uploads/AboveBelow3 (6).json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"train":[{"input":[[0,0,0,0,0,0,0,0],[0,3,3,3,0,0,0,0],[0,0,0,0,0,0,0,0],[0,4,4,4,0,0,0,0],[0,4,4,4,0,0,0,0],[0,4,4,4,0,0,0,0],[0,0,0,0,0,3,3,3],[0,0,3,3,3,0,0,0]],"output":[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,3,3,3,0,0,0,0],[0,4,4,4,0,0,0,0],[0,4,4,4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