Spaces:
Runtime error
Runtime error
KwabenaMufasa
commited on
Commit
•
0e56316
1
Parent(s):
0f7205d
Upload 4 files
Browse files- .gitattributes +1 -0
- API_app.py +96 -0
- Dockerfile (1).txt +28 -0
- P6_toolkit +3 -0
- requirements (1).txt +4 -0
.gitattributes
CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
P6_toolkit filter=lfs diff=lfs merge=lfs -text
|
API_app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
FastAPI script for Sepssis and model prediction
|
3 |
+
Author: Equity
|
4 |
+
Date: May.30th 2023
|
5 |
+
"""
|
6 |
+
|
7 |
+
|
8 |
+
# The library for the API Code
|
9 |
+
from fastapi import FastAPI
|
10 |
+
import pickle
|
11 |
+
import uvicorn
|
12 |
+
from pydantic import BaseModel
|
13 |
+
import pandas as pd
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
# Declare the data with its components and their type
|
18 |
+
class model_input(BaseModel):
|
19 |
+
|
20 |
+
PRG: int
|
21 |
+
PL: int
|
22 |
+
PR: int
|
23 |
+
SK: int
|
24 |
+
TS: int
|
25 |
+
M11: float
|
26 |
+
BD2: float
|
27 |
+
Age: int
|
28 |
+
Insurance:int
|
29 |
+
|
30 |
+
|
31 |
+
app = FastAPI(title = 'Sepssis API',
|
32 |
+
description = 'An API that takes input and display the predictions',
|
33 |
+
version = '0.1.0')
|
34 |
+
|
35 |
+
# Load the saved data
|
36 |
+
toolkit = "P6_toolkit"
|
37 |
+
|
38 |
+
def load_toolkit(filepath = toolkit):
|
39 |
+
with open(toolkit, "rb") as file:
|
40 |
+
loaded_toolkit = pickle.load(file)
|
41 |
+
return loaded_toolkit
|
42 |
+
|
43 |
+
toolkit = load_toolkit()
|
44 |
+
scaler = toolkit["scaler"]
|
45 |
+
model = toolkit["model"]
|
46 |
+
|
47 |
+
|
48 |
+
@app.get("/")
|
49 |
+
async def hello():
|
50 |
+
return "Welcome to our model API"
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
@app.post("/Sepssis")
|
55 |
+
async def prediction(input:model_input):
|
56 |
+
data = {
|
57 |
+
'PRG': input.PRG,
|
58 |
+
'PL': input.PL,
|
59 |
+
'PR': input.PR,
|
60 |
+
'SK': input.SK,
|
61 |
+
'TS': input.TS,
|
62 |
+
'M11': input.M11,
|
63 |
+
'BD2': input.BD2,
|
64 |
+
'Age': input.Age,
|
65 |
+
'Insurance': input.Insurance,
|
66 |
+
}
|
67 |
+
|
68 |
+
# prepare the data as a dataframe
|
69 |
+
df = pd.DataFrame(data, index=[0])
|
70 |
+
|
71 |
+
|
72 |
+
#numerical features
|
73 |
+
numeric_columns = [ 'PRG', 'PL', 'PR', 'SK', 'TS', 'M11', 'BD2', 'Age','Insurance']
|
74 |
+
|
75 |
+
#scaling
|
76 |
+
Scaler = scaler.transform(df[numeric_columns])
|
77 |
+
Scaled = pd.DataFrame(Scaler)
|
78 |
+
prediction = model.predict(Scaled).tolist()
|
79 |
+
probability = model.predict_proba(Scaled)
|
80 |
+
|
81 |
+
|
82 |
+
# Labelling Model output
|
83 |
+
if (prediction[0] < 0.5):
|
84 |
+
prediction = "Negative. This person has no Sepssis"
|
85 |
+
else:
|
86 |
+
prediction = "Positive. This person has Sepssis"
|
87 |
+
data['prediction'] = prediction
|
88 |
+
return data
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
# Launch the app
|
95 |
+
if __name__ == "__main__":
|
96 |
+
uvicorn.run("API_app:app",host = '0.0.0.0', port = 7860)
|
Dockerfile (1).txt
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
FROM python:3.9
|
4 |
+
|
5 |
+
WORKDIR /code
|
6 |
+
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
10 |
+
|
11 |
+
# Set up a new user named "user" with user ID 1000
|
12 |
+
RUN useradd -m -u 1000 user
|
13 |
+
# Switch to the "user" user
|
14 |
+
USER user
|
15 |
+
# Set home to the user's home directory
|
16 |
+
ENV HOME=/home/user \
|
17 |
+
PATH=/home/user/.local/bin:$PATH
|
18 |
+
|
19 |
+
# Set the working directory to the user's home directory
|
20 |
+
WORKDIR $HOME/app
|
21 |
+
|
22 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
23 |
+
COPY --chown=user . $HOME/app
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
#COPY . .
|
28 |
+
CMD ["python","API_app.py"]
|
P6_toolkit
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67301fa0e7ceab779e3047c8d399db2c83075496b832c5bdd93ecb5399bd5657
|
3 |
+
size 1178776
|
requirements (1).txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pytest
|
2 |
+
scikit-learn
|
3 |
+
fastapi[all]
|
4 |
+
pandas
|