Queensly commited on
Commit
ee259c3
1 Parent(s): 26e43fa

Added files

Browse files
Files changed (3) hide show
  1. Dockerfile +22 -2
  2. main.py +53 -3
  3. requirements.txt +3 -1
Dockerfile CHANGED
@@ -17,6 +17,18 @@
17
 
18
  # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  FROM python:3.9
21
 
22
  WORKDIR /code
@@ -25,7 +37,15 @@ COPY ./requirements.txt /code/requirements.txt
25
 
26
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
27
 
28
- COPY . .
 
 
 
 
 
 
 
29
 
30
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
31
 
 
 
17
 
18
  # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
19
 
20
+ # FROM python:3.9
21
+
22
+ # WORKDIR /code
23
+
24
+ # COPY ./requirements.txt /code/requirements.txt
25
+
26
+ # RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
27
+
28
+ # COPY . .
29
+
30
+ # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
31
+
32
  FROM python:3.9
33
 
34
  WORKDIR /code
 
37
 
38
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
39
 
40
+ RUN useradd -m -u 1000 user
41
+
42
+ USER user
43
+
44
+ ENV HOME=/home/user \
45
+ PATH=/home/user/.local/bin:$PATH
46
+
47
+ WORKDIR $HOME/app
48
 
49
+ COPY --chown=user . $HOME/app
50
 
51
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py CHANGED
@@ -1,7 +1,57 @@
1
  from fastapi import FastAPI
 
 
 
2
 
3
  app = FastAPI()
4
 
5
- @app.get("/")
6
- def read_root():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ import pickle
3
+ 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
+ @app.get('/Predict_Sepsis')
27
+ async def predict(Plasma_glucose: int, Blood_Work_Result_1: int,
28
+ Blood_Pressure: int, Blood_Work_Result_2: int,
29
+ Blood_Work_Result_3: int, Body_mass_index: float,
30
+ Blood_Work_Result_4: float,Age: int, Insurance:float):
31
+
32
+ data = pd.DataFrame({'Plasma glucose': [Plasma_glucose], 'Blood Work Result-1': [Blood_Work_Result_1],
33
+ 'Blood Pressure': [Blood_Pressure], 'Blood Work Result-2': [Blood_Work_Result_2],
34
+ 'Blood Work Result-3': [Blood_Work_Result_3], 'Body mass index': [Body_mass_index],
35
+ 'Blood Work Result-4': [Blood_Work_Result_4], 'Age': [Age], 'Insurance':[Insurance]})
36
+
37
+ data_prepared = pipeline_processing.transform(data)
38
+
39
+ model_output = ml_model.predict(data_prepared).tolist()
40
+
41
+ prediction = make_prediction(model_output)
42
+
43
+ return prediction
44
+
45
+
46
+
47
+
48
+ def make_prediction(data_prepared):
49
+
50
+ output_pred = data_prepared
51
+
52
+ if output_pred == 0:
53
+ output_pred = "Sepsis status is Negative"
54
+ else:
55
+ output_pred = "Sepsis status is Positive"
56
+
57
+ return output_pred
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  fastapi[all]
2
- uvicorn[standard]
 
 
 
1
  fastapi[all]
2
+ uvicorn[standard]
3
+ scikit-learn==1.2.2
4
+ pandas