aaronayitey commited on
Commit
49d2e92
1 Parent(s): 613a8a2

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +42 -0
main.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Query, HTTPException
2
+ import joblib
3
+ from pydantic import BaseModel
4
+ import pandas as pd
5
+
6
+
7
+ pipeline = joblib.load('./sepsis_classification_pipeline.joblib')
8
+ encoder = joblib.load('./label_encoder.joblib')
9
+ model = joblib.load('./random_forest_model.joblib')
10
+
11
+ app = FastAPI()
12
+
13
+
14
+ class features(BaseModel):
15
+ Age: int
16
+ Body_Mass_Index_BMI: float
17
+ Diastolic_Blood_Pressure: float
18
+ Plasma_Glucose: float
19
+ Triceps_Skinfold_Thickness: float
20
+ Elevated_Glucose: float
21
+ Diabetes_Pedigree_Function: float
22
+ Insulin_Levels: float
23
+
24
+
25
+ @app.post("/predict")
26
+ async def predict_sepsis(item: features):
27
+ try:
28
+ # Convert input data to DataFrame
29
+ input_data = pd.DataFrame([item.dict()])
30
+
31
+ # input_data = pipeline.named_steps.preprocessor.transform(input_data)
32
+
33
+ # Make predictions using the model
34
+ predictions = pipeline.predict(input_data)
35
+
36
+ # Decode predictions using the label encoder
37
+ decoded_predictions = encoder.inverse_transform(predictions)
38
+
39
+ return {"prediction": f'Patient is {decoded_predictions[0]}'}
40
+
41
+ except Exception as e:
42
+ raise HTTPException(status_code=500, detail=str(e))