woletee commited on
Commit
a37b981
·
1 Parent(s): 9b6d8e1

this is the last commit I made for toneight next I have to prepare on the notion and my model is also writting as well yesss now it is working

Browse files
Files changed (2) hide show
  1. app.py +25 -30
  2. templates/index.html +28 -5
app.py CHANGED
@@ -16,43 +16,40 @@ def tolist_safe(obj):
16
  def index():
17
  return render_template('index.html')
18
 
19
- @app.route('/upload', methods=['POST'])
20
- def upload():
21
- if 'file' not in request.files:
22
- return "No file part"
23
- file = request.files['file']
24
- if file.filename == '':
25
- return "No selected file"
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 = []
35
  predicted_HLCs = []
 
36
  for sample in data.get("train", []):
37
  input_grid = sample["input"]
38
  output_grid = sample["output"]
39
  concept_label, _ = run_inference(model, input_grid, output_grid)
40
  predicted_HLCs.append(concept_label)
41
  input_output_pairs.append((tolist_safe(input_grid), tolist_safe(output_grid)))
42
- predicted_HLCs = list(set(predicted_HLCs))
43
 
44
- # GP optimization
45
  best_program, generations = genetic_programming(
46
  input_output_pairs=input_output_pairs,
47
- population_size=200,
48
- generations=200,
49
  mutation_rate=0.2,
50
  crossover_rate=0.7,
51
  max_depth=3,
52
  predicted_HLCs=predicted_HLCs
53
  )
54
 
55
- # Evaluate GP program on test inputs
56
  test_pairs = []
57
  predicted_test_outputs = []
58
  for sample in data.get("test", []):
@@ -60,20 +57,18 @@ def upload():
60
  test_output = tolist_safe(sample["output"])
61
  test_pairs.append((test_input, test_output))
62
  try:
63
- pred = tolist_safe(best_program.evaluate(test_input))
64
  except Exception as e:
65
- print(f"Prediction error: {e}")
66
- pred = [["ERROR"]]
67
- predicted_test_outputs.append(pred)
 
 
 
 
 
 
68
 
69
- return render_template(
70
- "results.html",
71
- hlcs=predicted_HLCs,
72
- input_output_pairs=input_output_pairs,
73
- test_pairs=test_pairs,
74
- predicted_test_outputs=predicted_test_outputs,
75
- best_program=str(best_program)
76
- )
77
 
78
  if __name__ == '__main__':
79
  app.run(host='0.0.0.0', port=7860, debug=False)
 
16
  def index():
17
  return render_template('index.html')
18
 
19
+ @app.route('/submit_json', methods=['POST'])
20
+ def submit_json():
21
+ json_data = request.form.get('json_data')
22
+ if not json_data:
23
+ return "No JSON data provided"
 
 
24
 
25
+ try:
26
+ data = json.loads(json_data)
27
+ except json.JSONDecodeError:
28
+ return "Invalid JSON format!"
29
 
30
+ # Continue processing exactly as before:
 
 
 
31
  input_output_pairs = []
32
  predicted_HLCs = []
33
+
34
  for sample in data.get("train", []):
35
  input_grid = sample["input"]
36
  output_grid = sample["output"]
37
  concept_label, _ = run_inference(model, input_grid, output_grid)
38
  predicted_HLCs.append(concept_label)
39
  input_output_pairs.append((tolist_safe(input_grid), tolist_safe(output_grid)))
 
40
 
41
+ predicted_HLCs = list(set(predicted_HLCs))
42
  best_program, generations = genetic_programming(
43
  input_output_pairs=input_output_pairs,
44
+ population_size=300,
45
+ generations=500,
46
  mutation_rate=0.2,
47
  crossover_rate=0.7,
48
  max_depth=3,
49
  predicted_HLCs=predicted_HLCs
50
  )
51
 
52
+ # Evaluate test pairs (same as before)
53
  test_pairs = []
54
  predicted_test_outputs = []
55
  for sample in data.get("test", []):
 
57
  test_output = tolist_safe(sample["output"])
58
  test_pairs.append((test_input, test_output))
59
  try:
60
+ predicted = tolist_safe(best_program.evaluate(test_input))
61
  except Exception as e:
62
+ predicted = [["ERROR"]]
63
+ predicted_test_outputs.append(predicted)
64
+
65
+ return render_template("results.html",
66
+ hlcs=predicted_HLCs,
67
+ input_output_pairs=input_output_pairs,
68
+ test_pairs=test_pairs,
69
+ predicted_test_outputs=predicted_test_outputs,
70
+ best_program=str(best_program))
71
 
 
 
 
 
 
 
 
 
72
 
73
  if __name__ == '__main__':
74
  app.run(host='0.0.0.0', port=7860, debug=False)
templates/index.html CHANGED
@@ -2,13 +2,36 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>Upload ARC Task</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  </head>
7
  <body>
8
- <h1>Upload ARC Task File</h1>
9
- <form action="/upload" method="post" enctype="multipart/form-data">
10
- <input type="file" name="file" accept=".json" required>
11
- <button type="submit">Upload</button>
 
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
+ padding: 20px;
10
+ text-align: center;
11
+ }
12
+
13
+ textarea {
14
+ width: 90%;
15
+ height: 400px;
16
+ font-family: monospace;
17
+ font-size: 14px;
18
+ padding: 10px;
19
+ margin-bottom: 20px;
20
+ }
21
+
22
+ button {
23
+ padding: 10px 20px;
24
+ font-size: 16px;
25
+ cursor: pointer;
26
+ }
27
+ </style>
28
  </head>
29
  <body>
30
+ <h1>Paste ARC Task JSON</h1>
31
+ <form action="/submit_json" method="post">
32
+ <textarea name="json_data" placeholder="Paste your ARC JSON here..." required></textarea>
33
+ <br>
34
+ <button type="submit">Submit</button>
35
  </form>
36
  </body>
37
  </html>