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 # Load the pickled XGBoost model 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)") ): #prepare input features for prediction input_features = [prg,pl,pr,sk,ts,m11,bd2,age] #Make predictions using the loaded model 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 # Include the prediction in the response } ) # class Item(BaseModel): # name: str # price: float # is_offer: Union[bool, None] = None # @app.get("/") # def read_root(): # return {"Hello": "World"} # @app.get("/items/{item_id}") # def read_item(item_id: int, q: Union[str, None] = None): # return {"item_id": item_id, "q": q} # @app.put("/items/{item_id}") # def update_item(item_id: int, item: Item): # return {"item_name": item.name, "item_id": item_id} # @app.get("/display") # def display_params(request: Request, item_id: int, q: Union[str, None] = None): # return templates.TemplateResponse("display_params.html", {"request": request, "item_id": item_id, "q": q})