Kennymaur commited on
Commit
ce6144f
·
1 Parent(s): c736867

main.py uploaded

Browse files
Files changed (1) hide show
  1. main.py +51 -0
main.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException, Query
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ app = FastAPI()
6
+
7
+ # Load the sepsis prediction model
8
+ model = joblib.load('XGB.joblib')
9
+
10
+ @app.get("/")
11
+ async def read_root():
12
+ return {"message": "Sepsis Prediction API using FastAPI"}
13
+
14
+ def classify(prediction):
15
+ if prediction == 0:
16
+ return "Patient does not have sepsis"
17
+ else:
18
+ return "Patient has sepsis"
19
+
20
+ @app.get("/predict/")
21
+ async def predict_sepsis(
22
+ prg: float = Query(..., description="Plasma glucose"),
23
+ pl: float = Query(..., description="Blood Work Result-1 (mu U/ml)"),
24
+ pr: float = Query(..., description="Blood Pressure (mm Hg)"),
25
+ sk: float = Query(..., description="Blood Work Result-2 (mm)"),
26
+ ts: float = Query(..., description="Blood Work Result-3 (mu U/ml)"),
27
+ m11: float = Query(..., description="Body mass index (weight in kg/(height in m)^2"),
28
+ bd2: float = Query(..., description="Blood Work Result-4 (mu U/ml)"),
29
+ age: int = Query(..., description="Patient's age (years)")
30
+ ):
31
+ input_data = [prg, pl, pr, sk, ts, m11, bd2, age]
32
+
33
+ input_df = pd.DataFrame([input_data], columns=[
34
+ "Plasma glucose", "Blood Work Result-1", "Blood Pressure",
35
+ "Blood Work Result-2", "Blood Work Result-3",
36
+ "Body mass index", "Blood Work Result-4", "Age"
37
+ ])
38
+
39
+ pred = model.predict(input_df)
40
+ output = classify(pred[0])
41
+
42
+ response = {
43
+ "prediction": output
44
+ }
45
+
46
+ return response
47
+
48
+ # Run the app using Uvicorn
49
+ if __name__ == "__main__":
50
+ import uvicorn
51
+ uvicorn.run(app, host="127.0.0.1", port=7860)