Spaces:
Runtime error
Runtime error
Lambang
commited on
Commit
·
97efcb8
1
Parent(s):
77bf0a9
dada
Browse files
main.py
CHANGED
@@ -4,60 +4,14 @@ import uvicorn
|
|
4 |
import pandas as pd
|
5 |
|
6 |
app = FastAPI()
|
7 |
-
|
8 |
-
# @app.get("/")
|
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 |
-
|
31 |
-
|
32 |
-
@app.get('/Predict_Sepsis')
|
33 |
-
async def predict(Plasma_glucose: int, Blood_Work_Result_1: int,
|
34 |
-
Blood_Pressure: int, Blood_Work_Result_2: int,
|
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 |
-
|
48 |
-
|
49 |
-
return prediction
|
50 |
-
|
51 |
|
52 |
|
53 |
-
|
54 |
-
def make_prediction(data_prepared):
|
55 |
-
|
56 |
-
output_pred = data_prepared
|
57 |
-
|
58 |
-
if output_pred == 0:
|
59 |
-
output_pred = "Sepsis status is Negative"
|
60 |
-
else:
|
61 |
-
output_pred = "Sepsis status is Positive"
|
62 |
-
|
63 |
-
return output_pred
|
|
|
4 |
import pandas as pd
|
5 |
|
6 |
app = FastAPI()
|
7 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
#Endpoints
|
9 |
#Root endpoints
|
10 |
@app.get("/")
|
11 |
+
async def root():
|
12 |
+
# Dapatkan URL publik dari ngrok
|
13 |
+
ngrok_url = "Tidak Ada URL Publik (ngrok belum selesai memulai)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
return {"message": "Hello, World!", "ngrok_url": ngrok_url}
|
|
|
|
|
|
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|