Update src/app.py
Browse files- src/app.py +13 -11
src/app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import pickle
|
| 4 |
import pandas as pd
|
|
@@ -10,7 +10,7 @@ app = FastAPI(
|
|
| 10 |
)
|
| 11 |
|
| 12 |
# Load the model and key components
|
| 13 |
-
with open('model_and_key_components.pkl', 'rb') as file:
|
| 14 |
loaded_components = pickle.load(file)
|
| 15 |
|
| 16 |
loaded_model = loaded_components['model']
|
|
@@ -19,14 +19,14 @@ loaded_scaler = loaded_components['scaler']
|
|
| 19 |
|
| 20 |
# Define the input data structure using Pydantic BaseModel
|
| 21 |
class InputData(BaseModel):
|
| 22 |
-
PRG: int
|
| 23 |
-
PL: float
|
| 24 |
-
PR: float
|
| 25 |
-
SK: float
|
| 26 |
-
TS: int
|
| 27 |
-
M11: float
|
| 28 |
-
BD2: float
|
| 29 |
-
Age: int
|
| 30 |
|
| 31 |
# Define the output data structure using Pydantic BaseModel
|
| 32 |
class OutputData(BaseModel):
|
|
@@ -55,6 +55,7 @@ async def root():
|
|
| 55 |
message = "Welcome to your Sepsis Classification API! Click [here](/docs) to access the API documentation."
|
| 56 |
return {"message": message}
|
| 57 |
|
|
|
|
| 58 |
@app.post("/predict/", response_model=OutputData)
|
| 59 |
async def predict_sepsis(input_data: InputData):
|
| 60 |
try:
|
|
@@ -62,10 +63,11 @@ async def predict_sepsis(input_data: InputData):
|
|
| 62 |
sepsis_status = make_predictions(input_data_scaled_df)
|
| 63 |
return {"Sepsis": sepsis_status}
|
| 64 |
except Exception as e:
|
|
|
|
| 65 |
# Handle exceptions and return an error response
|
| 66 |
raise HTTPException(status_code=500, detail=str(e))
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
import uvicorn
|
| 70 |
# Run the FastAPI application on the local host and port 8000
|
| 71 |
-
uvicorn.run(app, host="127.0.0.1", port=8000)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import pickle
|
| 4 |
import pandas as pd
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
# Load the model and key components
|
| 13 |
+
with open('/model_and_key_components.pkl', 'rb') as file:
|
| 14 |
loaded_components = pickle.load(file)
|
| 15 |
|
| 16 |
loaded_model = loaded_components['model']
|
|
|
|
| 19 |
|
| 20 |
# Define the input data structure using Pydantic BaseModel
|
| 21 |
class InputData(BaseModel):
|
| 22 |
+
PRG: int
|
| 23 |
+
PL: float
|
| 24 |
+
PR: float
|
| 25 |
+
SK: float
|
| 26 |
+
TS: int
|
| 27 |
+
M11: float
|
| 28 |
+
BD2: float
|
| 29 |
+
Age: int
|
| 30 |
|
| 31 |
# Define the output data structure using Pydantic BaseModel
|
| 32 |
class OutputData(BaseModel):
|
|
|
|
| 55 |
message = "Welcome to your Sepsis Classification API! Click [here](/docs) to access the API documentation."
|
| 56 |
return {"message": message}
|
| 57 |
|
| 58 |
+
|
| 59 |
@app.post("/predict/", response_model=OutputData)
|
| 60 |
async def predict_sepsis(input_data: InputData):
|
| 61 |
try:
|
|
|
|
| 63 |
sepsis_status = make_predictions(input_data_scaled_df)
|
| 64 |
return {"Sepsis": sepsis_status}
|
| 65 |
except Exception as e:
|
| 66 |
+
|
| 67 |
# Handle exceptions and return an error response
|
| 68 |
raise HTTPException(status_code=500, detail=str(e))
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
import uvicorn
|
| 72 |
# Run the FastAPI application on the local host and port 8000
|
| 73 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|