-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
117 lines (96 loc) · 3.22 KB
/
main.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
import firstTry
import json
import httpx
import logging
logger = logging.getLogger(__name__)
app = FastAPI()
# Allow CORS for all origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # You can replace "*" with specific origins if needed
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE"],
allow_headers=["*"],
)
@app.get("/process_data/")
async def process_data(param1: float, param2: float, param3: float, param4: float, param5: float, param6: float
, param7: float, param8: float, param9: float):
"""
'Grid', 'Comfort', 'Tech', 'Visualize', 'Volume', 'Reliability', 'Security', 'Service', "Insulation"
"""
# easy to use
input_values = [param1, param2, param3, param4, param5, param6, param7, param8, param9]
# Predict car model
# Call another endpoint
async with httpx.AsyncClient() as client:
response = await client.get("https://car-predictor-backend-db.onrender.com/model-stats/")
models = []
model_names = []
grid = []
comfort = []
tech = []
visualize = []
volume = []
reliability = []
security = []
service = []
insulation = []
for model in response.json():
model_names.append(model['modelName'])
grid .append(model['Grid'])
comfort.append(model['Comfort'])
tech.append(model['Tech'])
visualize.append(model['Visualize'])
volume.append(model['Volume'])
reliability.append(model['Reliability'])
security.append(model['Security'])
service.append(model['Service'])
insulation.append(model['Insulation'])
models.append({
"Grid" : grid,
"Models" : model_names
})
models.append({
"Comfort": grid,
"Models": model_names
})
models.append({
"Tech": grid,
"Models": model_names
})
models.append({
"Visualize": grid,
"Models": model_names
})
models.append({
"Volume": grid,
"Models": model_names
})
models.append({
"Reliability": grid,
"Models": model_names
})
models.append({
"Security": grid,
"Models": model_names
})
models.append({
"Service": grid,
"Models": model_names
})
models.append({
"Insulation": grid,
"Models": model_names
})
predicted_model = ""
clf, le, X = firstTry.train_models(models)
predicted_model = firstTry.predict_car_model(input_values, clf, le, X)
print("Predicted car model easy to use:", predicted_model)
# Perform processing here
result = {
"Predicted Model": predicted_model
}
json_result = json.dumps(result)
return Response(content=json_result, media_type="application/json")