-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (41 loc) · 1.31 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
import joblib
import pandas as pd
from fastapi import FastAPI, Form, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
app = FastAPI()
model = joblib.load(open("./dumps/model.pkl", "rb"))
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("base.html", {"request": request})
@app.post("/predict", response_class=HTMLResponse)
async def predict(
request: Request,
pregnancies: int = Form(...),
glucose: int = Form(...),
bloodpressure: int = Form(...),
skinthickness: int = Form(...),
insulin: int = Form(...),
bmi: float = Form(...),
dpf: float = Form(...),
age: int = Form(...),
):
data = pd.DataFrame(
[[pregnancies, glucose, bloodpressure, skinthickness, insulin, bmi, dpf, age]],
columns=[
"Pregnancies",
"Glucose",
"BloodPressure",
"SkinThickness",
"Insulin",
"BMI",
"DPF",
"Age",
],
)
prediction = model.predict(data)
print(prediction)
return templates.TemplateResponse(
"result.html", context={"prediction": prediction, "request": request}
)