File size: 1,529 Bytes
29a0c45
 
3052d0f
 
 
 
29a0c45
 
 
3052d0f
29a0c45
 
 
3052d0f
29a0c45
 
 
 
 
 
 
 
 
 
 
 
 
3052d0f
 
 
 
29a0c45
3052d0f
 
 
 
 
 
 
 
 
29a0c45
 
 
 
 
 
 
 
 
3052d0f
29a0c45
3052d0f
29a0c45
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, request, render_template, redirect, url_for
import os
import json
from Vit_concept import run_inference, model
from GP import genetic_programming

app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload():
    if 'file' not in request.files:
        return "No file part"
    file = request.files['file']
    if file.filename == '':
        return "No selected file"

    filepath = os.path.join(UPLOAD_FOLDER, file.filename)
    file.save(filepath)

    with open(filepath, 'r') as f:
        data = json.load(f)

    input_output_pairs = []
    predicted_HLCs = []

    for sample in data.get("train", []):
        input_grid = sample["input"]
        output_grid = sample["output"]

        concept_label, _ = run_inference(model, input_grid, output_grid)
        predicted_HLCs.append(concept_label)
        input_output_pairs.append((input_grid, output_grid))

    predicted_HLCs = list(set(predicted_HLCs))

    best_program, generations = genetic_programming(
        input_output_pairs=input_output_pairs,
        population_size=300,
        generations=500,
        mutation_rate=0.2,
        crossover_rate=0.7,
        max_depth=3,
        predicted_HLCs=predicted_HLCs
    )

    return render_template("results.html", hlcs=predicted_HLCs, program=str(best_program))

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=7860)