Sonny4Sonnix commited on
Commit
5416df1
·
1 Parent(s): 8d6f867

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +83 -0
main.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.templating import Jinja2Templates
4
+ from fastapi import FastAPI, Query, Request
5
+
6
+ from pydantic import BaseModel
7
+ from transformers import pipeline
8
+ from typing import Union
9
+ import pickle
10
+ import joblib
11
+
12
+
13
+ # Load the pickled XGBoost model
14
+ xgb_model = joblib.load("xgb_model.joblib")
15
+
16
+
17
+ app = FastAPI()
18
+ templates = Jinja2Templates(directory="templates")
19
+
20
+ @app.get("/display")
21
+ def display_params(
22
+ request: Request,
23
+ prg: float = Query(..., description="Plasma glucose"),
24
+ pl: float = Query(..., description="Blood Work Result-1 (mu U/ml)"),
25
+ pr: float = Query(..., description="Blood Pressure (mm Hg)"),
26
+ sk: float = Query(..., description="Blood Work Result-2 (mm)"),
27
+ ts: float = Query(..., description="Blood Work Result-3 (mu U/ml)"),
28
+ m11: float = Query(..., description="Body mass index (weight in kg/(height in m)^2"),
29
+ bd2: float = Query(..., description="Blood Work Result-4 (mu U/ml)"),
30
+ age: int = Query(..., description="Patient's age (years)")
31
+ ):
32
+ #prepare input features for prediction
33
+ input_features = [prg,pl,pr,sk,ts,m11,bd2,age]
34
+
35
+ #Make predictions using the loaded model
36
+ prediction = xgb_model.predict([input_features])[0]
37
+
38
+ return templates.TemplateResponse(
39
+ "display_params.html",
40
+ {
41
+ "request": request,
42
+ "prg": prg,
43
+ "pl": pl,
44
+ "pr": pr,
45
+ "sk": sk,
46
+ "ts": ts,
47
+ "m11": m11,
48
+ "bd2": bd2,
49
+ "age": age
50
+ "prediction": prediction # Include the prediction in the response
51
+ }
52
+ )
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ # class Item(BaseModel):
62
+ # name: str
63
+ # price: float
64
+ # is_offer: Union[bool, None] = None
65
+
66
+
67
+ # @app.get("/")
68
+ # def read_root():
69
+ # return {"Hello": "World"}
70
+
71
+
72
+ # @app.get("/items/{item_id}")
73
+ # def read_item(item_id: int, q: Union[str, None] = None):
74
+ # return {"item_id": item_id, "q": q}
75
+
76
+
77
+ # @app.put("/items/{item_id}")
78
+ # def update_item(item_id: int, item: Item):
79
+ # return {"item_name": item.name, "item_id": item_id}
80
+
81
+ # @app.get("/display")
82
+ # def display_params(request: Request, item_id: int, q: Union[str, None] = None):
83
+ # return templates.TemplateResponse("display_params.html", {"request": request, "item_id": item_id, "q": q})