rasmodev commited on
Commit
a562d9d
·
1 Parent(s): 7f94efd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # Load the model and key components
7
+ with open('model_and_key_components.pkl', 'rb') as file:
8
+ loaded_components = pickle.load(file)
9
+
10
+ loaded_model = loaded_components['model']
11
+ loaded_scaler = loaded_components['scaler']
12
+
13
+ # Data Fields
14
+ data_fields = {
15
+ "PRG": "Number of pregnancies (applicable only to females)",
16
+ "PL": "Plasma glucose concentration (mg/dL)",
17
+ "PR": "Diastolic blood pressure (mm Hg)",
18
+ "SK": "Triceps skinfold thickness (mm)",
19
+ "TS": "2-hour serum insulin (mu U/ml)",
20
+ "M11": "Body mass index (BMI) (weight in kg / {(height in m)}^2)",
21
+ "BD2": "Diabetes pedigree function (mu U/ml)",
22
+ "Age": "Age of the patient (years)"
23
+ }
24
+
25
+ # Page Title
26
+ st.title("Sepsis Prediction App")
27
+
28
+ # Sidebar with Data Fields
29
+ st.sidebar.title("Input Data")
30
+ input_data = {}
31
+ for field, description in data_fields.items():
32
+ input_data[field] = st.sidebar.number_input(description, value=0.0)
33
+
34
+ # Function to preprocess input data
35
+ def preprocess_input_data(input_data):
36
+ numerical_cols = ['PRG', 'PL', 'PR', 'SK', 'TS', 'M11', 'BD2', 'Age']
37
+ input_data_scaled = loaded_scaler.transform([list(input_data.values())])
38
+ return pd.DataFrame(input_data_scaled, columns=numerical_cols)
39
+
40
+ # Function to make predictions
41
+ def make_predictions(input_data_scaled_df):
42
+ y_pred = loaded_model.predict(input_data_scaled_df)
43
+ sepsis_mapping = {0: 'Negative', 1: 'Positive'}
44
+ return sepsis_mapping[y_pred[0]]
45
+
46
+ # Predict Button
47
+ if st.sidebar.button("Predict Sepsis"):
48
+ try:
49
+ input_data_scaled_df = preprocess_input_data(input_data)
50
+ sepsis_status = make_predictions(input_data_scaled_df)
51
+ st.success(f"The predicted sepsis status is: {sepsis_status}")
52
+ except Exception as e:
53
+ st.error(f"An error occurred: {e}")
54
+
55
+ # Display Data Fields and Descriptions
56
+ st.sidebar.title("Data Fields")
57
+ for field, description in data_fields.items():
58
+ st.sidebar.text(f"{field}: {description}")
59
+
60
+ # About Section
61
+ st.sidebar.title("About")
62
+ st.sidebar.info(
63
+ "This app predicts sepsis based on medical input data. "
64
+ "It uses a machine learning model trained on a dataset of sepsis cases."
65
+ )
66
+
67
+ # Welcome Message
68
+ st.write(
69
+ "Welcome to the Sepsis Prediction App! Enter the medical data in the sidebar, "
70
+ "click 'Predict Sepsis', and get the prediction result."
71
+ )