slickdata commited on
Commit
e08cf32
·
1 Parent(s): e820ed6

Upload 14 files

Browse files
.Dockerignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv/
2
+ __pycache__/
Assets/Final_01_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02d2c340bf2e8a1977327fb4d92cf337d3106ee0a93a66ea50a87ce7db9fefbf
3
+ size 107062
Assets/Final_02_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d931a4eed525b88e7e39f617091e75fed694149f523e1183d03e6755ec2b045
3
+ size 280960
Assets/Final_03_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95146dc19fdd476db63b0129be3302f6ff270e9763b327f2179c306365c24c3d
3
+ size 33436
Assets/label_encoder.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36dfa139c49c8671caadcbb80691bbcaf63c4e38b98edc137eb2cfabcf7eb8dc
3
+ size 548
Assets/numerical_imputer.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e9b4073656b3acdc3ab91cea2949192549ec7c7b4d239754eca8db853ca0d6a
3
+ size 943
Assets/scaler.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c394755caeda935f17dcd6f78e49f5f5cac6639c1980b3c6479e3ec816f4b88
3
+ size 815
Data/Paitients_Files_Test.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,PRG,PL,PR,SK,TS,M11,BD2,Age,Insurance
Data/Paitients_Files_Train.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,PRG,PL,PR,SK,TS,M11,BD2,Age,Insurance,Sepssis
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python base image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /code
6
+
7
+ # Copy the requirements file to the working directory
8
+ COPY requirements.txt /code/requirements.txt
9
+
10
+ # Install the Python dependencies
11
+ RUN pip install -r requirements.txt
12
+
13
+ # Copy the application code to the working directory
14
+ COPY ./src /code/src
15
+
16
+ # Expose the port on which the application will run
17
+ EXPOSE 8000
18
+
19
+ # Run the FastAPI application using uvicorn server
20
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
LP6.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Notebook/LP6.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
main.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ import uvicorn
3
+ import os
4
+ import numpy as np
5
+ import pandas as pd
6
+ from sklearn.preprocessing import StandardScaler
7
+ from sklearn.impute import SimpleImputer
8
+ import joblib
9
+
10
+ app = FastAPI(debug=True)
11
+
12
+ def load_model():
13
+ cwd = os.getcwd()
14
+ destination = os.path.join(cwd, "Assets")
15
+
16
+ imputer_filepath = os.path.join(destination, "numerical_imputer.joblib")
17
+ scaler_filepath = os.path.join(destination, "scaler.joblib")
18
+ model_filepath = os.path.join(destination, "Final_01_model.joblib")
19
+
20
+ num_imputer = joblib.load(imputer_filepath)
21
+ scaler = joblib.load(scaler_filepath)
22
+ model = joblib.load(model_filepath)
23
+
24
+ return num_imputer, scaler, model
25
+
26
+ numerical_imputer, scaler, model = load_model()
27
+
28
+ @app.get("/")
29
+ async def read_root():
30
+ return {"message": "Welcome To The Sepsis Prediction API"}
31
+
32
+ @app.post("/predict_sepsis")
33
+ async def predict_sepsis(PRG: float, PL: float, PR: float, SK: float, TS: float, M11: float, BD2: float, Age: float, Insurance: int):
34
+ sepsis_data = {
35
+ 'PRG': PRG,
36
+ 'PL': PL,
37
+ 'PR': PR,
38
+ 'SK': SK,
39
+ 'TS': TS,
40
+ 'M11': M11,
41
+ 'BD2': BD2,
42
+ 'Age': Age,
43
+ 'Insurance': Insurance
44
+ }
45
+
46
+ input_data = pd.DataFrame([sepsis_data]) # Create a DataFrame from the dictionary
47
+
48
+ input_imputed = numerical_imputer.transform(input_data)
49
+ input_scaled = scaler.transform(input_imputed)
50
+
51
+ prediction = model.predict(input_scaled)
52
+
53
+ sepsis_status = "Positive" if prediction == 1 else "Negative"
54
+
55
+ probabilities = model.predict_proba(input_scaled)[0]
56
+ probability = probabilities[1] if prediction == 1 else probabilities[0]
57
+
58
+ if prediction == 1:
59
+ status_icon = "✔"
60
+ sepsis_explanation = "Sepsis is a life-threatening condition caused by an infection. A positive prediction suggests that the patient might be exhibiting sepsis symptoms and requires immediate medical attention."
61
+ else:
62
+ status_icon = "✘"
63
+ sepsis_explanation = "Sepsis is a life-threatening condition caused by an infection. A negative prediction suggests that the patient is not currently exhibiting sepsis symptoms."
64
+
65
+ statement = f"The patient's sepsis status is {sepsis_status} {status_icon} with a probability of {probability:.2f}. {sepsis_explanation}"
66
+
67
+ user_input_statement = f"Please note this is the user-inputted data: {sepsis_data}"
68
+
69
+ result = {
70
+ 'predicted_sepsis': sepsis_status,
71
+ 'statement': statement,
72
+ 'user_input_statement': user_input_statement,
73
+ 'probability': probability
74
+ }
75
+
76
+ return result
77
+
78
+ if __name__ == "__main__":
79
+ uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.100.0
2
+ gradio==3.36.1
3
+ huggingface-hub==0.16.4
4
+ joblib==1.3.1
5
+ matplotlib==3.7.2
6
+ matplotlib-inline==0.1.6
7
+ numpy==1.25.0
8
+ plotly==5.16.1
9
+ pydantic==2.0.2
10
+ pydantic_core==2.1.2
11
+ scikit-learn==1.3.0
12
+ scipy==1.11.1
13
+ seaborn==0.12.2
14
+ streamlit==1.24.1
15
+ threadpoolctl==3.1.0
16
+ uvicorn==0.22.0