-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (69 loc) · 2.51 KB
/
app.py
File metadata and controls
82 lines (69 loc) · 2.51 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
dataset = request.form.get('dataset')
model = request.form.get('model')
if not model: # If no model is selected, display all models for the selected dataset
return render_template("result.html", dataset=dataset, models=data[dataset])
return render_template("result.html", dataset=dataset, model=model)
# Load dataset and model options from data2.json
with open('static/data.json', 'r') as file:
data = json.load(file)
datasets = list(data.keys())
models = list(data[datasets[0]].keys())
return render_template("home.html", datasets=datasets, models=models)
@app.route('/result', methods=['POST'])
def result():
print("Result function called")
selected_dataset = request.form['dataset']
selected_model = request.form['model']
# Load data from the data2.json file
with open('static/data.json', "r") as json_file:
data = json.load(json_file)
print("Result function called 22")
# Extract model data for the selected dataset and model
dataset_data = data.get(selected_dataset, {})
model_data = dataset_data.get(selected_model, {})
print("Result function called 33")
print(model_data)
# Initialize variables
parameters = {}
rmse = 0
loss = 0
images = []
ev = {}
print("Result function called 44")
dq=[]
# Try to extract parameters, RMSE, loss, and images
try:
ev = {key: value for key, value in model_data.items() if key != 'image'}
print("ev", ev)
except Exception as e:
print(f"Error: {e}")
try:
parameters = model_data["best_params"]
print("p", parameters)
except Exception as e:
print(f"Error: {e}")
try:
rmse = model_data.get("rmse", 0)
print("r", rmse)
except Exception as e:
print(f"Error: {e}")
try:
loss = model_data.get("loss", 0)
print(loss, "l")
except Exception as e:
print(f"Error: {e}")
try:
images = model_data.get("image", [])
print(images, "i")
except Exception as e:
print(f"Error: {e}")
return render_template('result.html', dataset=selected_dataset, model=selected_model, ev=ev,
parameters=parameters, rmse=rmse, loss=loss, images=images)
if __name__ == '__main__':
app.run(debug=True)