Spaces:
Running
Running
Commit
·
0ed2ee7
1
Parent(s):
d687e0e
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import pickle
|
| 3 |
import uvicorn
|
|
@@ -5,59 +8,33 @@ import pandas as pd
|
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
-
|
| 9 |
-
# def read_root():
|
| 10 |
-
# return {"Hello": "World!"}
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Function to load pickle file
|
| 14 |
-
def load_pickle(filename):
|
| 15 |
-
with open(filename, 'rb') as file:
|
| 16 |
-
data = pickle.load(file)
|
| 17 |
-
return data
|
| 18 |
-
|
| 19 |
-
# Load pickle file
|
| 20 |
-
ml_components = load_pickle('ml_sepsis.pkl')
|
| 21 |
-
|
| 22 |
-
# Components in the pickle file
|
| 23 |
-
ml_model = ml_components['model']
|
| 24 |
-
pipeline_processing = ml_components['pipeline']
|
| 25 |
-
|
| 26 |
#Endpoints
|
| 27 |
#Root endpoints
|
| 28 |
@app.get("/")
|
| 29 |
def root():
|
| 30 |
-
return {"API": "
|
| 31 |
|
| 32 |
@app.get('/Predict_Sepsis')
|
| 33 |
-
async def predict(
|
| 34 |
-
|
| 35 |
-
Blood_Work_Result_3: int, Body_mass_index: float,
|
| 36 |
-
Blood_Work_Result_4: float,Age: int, Insurance:float):
|
| 37 |
|
| 38 |
-
data = pd.DataFrame({'Plasma glucose': [Plasma_glucose], 'Blood Work Result-1': [Blood_Work_Result_1],
|
| 39 |
-
'Blood Pressure': [Blood_Pressure], 'Blood Work Result-2': [Blood_Work_Result_2],
|
| 40 |
-
'Blood Work Result-3': [Blood_Work_Result_3], 'Body mass index': [Body_mass_index],
|
| 41 |
-
'Blood Work Result-4': [Blood_Work_Result_4], 'Age': [Age], 'Insurance':[Insurance]})
|
| 42 |
|
| 43 |
-
data_prepared = pipeline_processing.transform(data)
|
| 44 |
-
|
| 45 |
-
model_output = ml_model.predict(data_prepared).tolist()
|
| 46 |
|
| 47 |
-
prediction =
|
| 48 |
|
| 49 |
return prediction
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
-
def make_prediction(data_prepared):
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
|
|
|
| 1 |
+
# https://medium.com/@qacheampong/building-and-deploying-a-fastapi-app-with-hugging-face-9210e9b4a713
|
| 2 |
+
# https://huggingface.co/spaces/Queensly/FastAPI_in_Docker
|
| 3 |
+
|
| 4 |
from fastapi import FastAPI
|
| 5 |
import pickle
|
| 6 |
import uvicorn
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
#Endpoints
|
| 13 |
#Root endpoints
|
| 14 |
@app.get("/")
|
| 15 |
def root():
|
| 16 |
+
return {"API": "Sum of 2 Squares"}
|
| 17 |
|
| 18 |
@app.get('/Predict_Sepsis')
|
| 19 |
+
async def predict(number_1: int,
|
| 20 |
+
number_2: int,:
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
prediction = number_1**2+number_2**2
|
| 25 |
|
| 26 |
return prediction
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
+
# def make_prediction(data_prepared):
|
| 32 |
|
| 33 |
+
# output_pred = data_prepared
|
| 34 |
|
| 35 |
+
# if output_pred == 0:
|
| 36 |
+
# output_pred = "Sepsis status is Negative"
|
| 37 |
+
# else:
|
| 38 |
+
# output_pred = "Sepsis status is Positive"
|
| 39 |
|
| 40 |
+
# return output_pred
|