Ausbel commited on
Commit
7c3d8de
1 Parent(s): 1cae00f

Create main.py

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