|
from fastapi import FastAPI |
|
from fastapi.responses import HTMLResponse |
|
from fastapi.templating import Jinja2Templates |
|
from fastapi import FastAPI, Query, Request |
|
|
|
from pydantic import BaseModel |
|
from transformers import pipeline |
|
from typing import Union |
|
import pickle |
|
import joblib |
|
|
|
|
|
|
|
xgb_model = joblib.load("xgb_model.joblib") |
|
|
|
|
|
app = FastAPI() |
|
templates = Jinja2Templates(directory="templates") |
|
|
|
@app.get("/display") |
|
def display_params( |
|
request: Request, |
|
prg: float = Query(..., description="Plasma glucose"), |
|
pl: float = Query(..., description="Blood Work Result-1 (mu U/ml)"), |
|
pr: float = Query(..., description="Blood Pressure (mm Hg)"), |
|
sk: float = Query(..., description="Blood Work Result-2 (mm)"), |
|
ts: float = Query(..., description="Blood Work Result-3 (mu U/ml)"), |
|
m11: float = Query(..., description="Body mass index (weight in kg/(height in m)^2"), |
|
bd2: float = Query(..., description="Blood Work Result-4 (mu U/ml)"), |
|
age: int = Query(..., description="Patient's age (years)") |
|
): |
|
|
|
input_features = [prg,pl,pr,sk,ts,m11,bd2,age] |
|
|
|
|
|
prediction = xgb_model.predict([input_features])[0] |
|
|
|
return templates.TemplateResponse( |
|
"display_params.html", |
|
{ |
|
"request": request, |
|
"prg": prg, |
|
"pl": pl, |
|
"pr": pr, |
|
"sk": sk, |
|
"ts": ts, |
|
"m11": m11, |
|
"bd2": bd2, |
|
"age": age |
|
"prediction": prediction |
|
} |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|