Winnie-Kay commited on
Commit
10b1799
1 Parent(s): 5f6aabf

files upload

Browse files
Files changed (6) hide show
  1. dockerfile +22 -0
  2. main.py +61 -0
  3. numerical_imputer.joblib +3 -0
  4. requirements.txt +6 -0
  5. scaler.joblib +3 -0
  6. sepsis_model.joblib +3 -0
dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #specifing the docker image
2
+ FROM python:3.9-slim
3
+
4
+ #setting working directory where my app code is in.
5
+ WORKDIR /app
6
+
7
+ #copying requirements file from project woekdir to docker dir
8
+ COPY requirements.txt .
9
+
10
+ RUN pip install -r requirements.txt
11
+
12
+ #copying the entire project code to the container
13
+ COPY app.py .
14
+
15
+ #copying the model to the docker dir
16
+ COPY key_comp key_comp
17
+
18
+ #specfying the port that my fastapi is in
19
+ EXPOSE 8000
20
+
21
+ # Run the FastAPI application
22
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import uvicorn
4
+ import pandas as pd
5
+ import joblib
6
+
7
+ app = FastAPI()
8
+
9
+
10
+ #Load your saved model and components
11
+ def load_model():
12
+ num_imputer = joblib.load('numerical_imputer.joblib')
13
+ scaler = joblib.load('scaler.joblib')
14
+ model = joblib.load('sepsis_model.joblib')
15
+ return num_imputer, scaler, model
16
+
17
+ #Create a class for taking inputs
18
+ class UserInput(BaseModel):
19
+ PRG: int
20
+ PL: int
21
+ PR: int
22
+ SK: int
23
+ TS: int
24
+ M11: float
25
+ BD2: float
26
+ Age: int
27
+ Insurance:int
28
+
29
+ @app.get('/')
30
+ async def index():
31
+ return {"Sepsis API": "Sepsis Prediction"}
32
+
33
+ #get data and make predictions
34
+ @app.post('/predict/')
35
+ async def predict(UserInput: UserInput):
36
+
37
+ data = {
38
+ 'PRG': UserInput.PRG,
39
+ 'PL': UserInput.PL,
40
+ 'PR': UserInput.PR,
41
+ 'SK': UserInput.SK,
42
+ 'TS': UserInput.TS,
43
+ 'M11': UserInput.M11,
44
+ 'BD2': UserInput.BD2,
45
+ 'Age': UserInput.Age,
46
+ 'Insurance': UserInput.Insurance,
47
+ }
48
+ df = pd.DataFrame(data, index=[0])
49
+ num_col = [ 'PRG', 'PL', 'PR', 'SK', 'TS', 'M11', 'BD2', 'Age','Insurance']
50
+ num_imputer, scaler, model = load_model()
51
+ #Scale numerical colums
52
+ scaled_col = scaler.transform(df[num_col])
53
+ df2 = pd.DataFrame(scaled_col)
54
+ prediction = model.predict(df2).tolist()
55
+
56
+ if (prediction[0] == 1):
57
+ result = "Positive Sepsis"
58
+ else:
59
+ result = "Negative Sepsis"
60
+
61
+ return{"result":result}
numerical_imputer.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d43c1f7b7b8b97db860ddf4ddf83741bc781d08b5b0f610ffd2cecc4d8655143
3
+ size 580
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pytest
2
+ scikit-learn
3
+ fastapi[all]
4
+ pydantic
5
+ pandas
6
+ joblib
scaler.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11fe6ca76b5671f97668579d398794900497b324d65a21435abdb89222346a1d
3
+ size 665
sepsis_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfbe6ecd57f0bc5f1ec468216f837130436b0f1dea23fe5eba5fb1016ff3a92d
3
+ size 1783