File size: 3,121 Bytes
a562d9d
 
 
 
 
dd8cdb5
 
 
8a5bdef
 
 
318b7fb
8a5bdef
 
 
dd8cdb5
 
 
 
 
 
 
a562d9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318b7fb
c64d12f
a562d9d
ed34a12
 
 
a562d9d
 
 
 
 
 
 
 
 
 
 
 
318b7fb
 
 
 
 
 
 
 
 
 
 
 
 
8a5bdef
0b12140
a562d9d
 
 
 
 
 
 
 
8a5bdef
a562d9d
dd8cdb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import streamlit as st
import pickle
import pandas as pd
import numpy as np

# Page Title with Style
st.title("🩸 Sepsis Prediction App")
st.markdown("---")

# Welcome Message with Style
st.write(
    "👋 Welcome to the Sepsis Prediction App! Enter the medical data in the input fields below, "
    "click 'Predict Sepsis', and get the prediction result."
)

# About Section with Style
st.sidebar.title("ℹ️ About")
st.sidebar.info(
    "This app predicts sepsis based on medical input data. "
    "It uses a machine learning model trained on a dataset of sepsis cases."
)

# Load the model and key components
with open('model_and_key_components.pkl', 'rb') as file:
    loaded_components = pickle.load(file)

loaded_model = loaded_components['model']
loaded_scaler = loaded_components['scaler']

# Data Fields
data_fields = {
    "PRG": "Number of pregnancies (applicable only to females)",
    "PL": "Plasma glucose concentration (mg/dL)",
    "PR": "Diastolic blood pressure (mm Hg)",
    "SK": "Triceps skinfold thickness (mm)",
    "TS": "2-hour serum insulin (mu U/ml)",
    "M11": "Body mass index (BMI) (weight in kg / {(height in m)}^2)",
    "BD2": "Diabetes pedigree function (mu U/ml)",
    "Age": "Age of the patient (years)"
}

# Organize input fields into two columns
col1, col2 = st.columns(2)

# Initialize input_data dictionary
input_data = {}

# Function to preprocess input data
def preprocess_input_data(input_data):
    numerical_cols = ['PRG', 'PL', 'PR', 'SK', 'TS', 'M11', 'BD2', 'Age']
    input_data_scaled = loaded_scaler.transform([list(input_data.values())])
    return pd.DataFrame(input_data_scaled, columns=numerical_cols)

# Function to make predictions
def make_predictions(input_data_scaled_df):
    y_pred = loaded_model.predict(input_data_scaled_df)
    sepsis_mapping = {0: 'Negative', 1: 'Positive'}
    return sepsis_mapping[y_pred[0]]

# Input Data Fields in two columns
with col1:
    input_data["PRG"] = st.number_input("Number of Pregnancies", value=0.0)
    input_data["PL"] = st.number_input("Plasma Glucose Concentration (mg/dL)", value=0.0)
    input_data["PR"] = st.number_input("Diastolic Blood Pressure (mm Hg)", value=0.0)
    input_data["SK"] = st.number_input("Triceps Skinfold Thickness (mm)", value=0.0)

with col2:
    input_data["TS"] = st.number_input("2-Hour Serum Insulin (mu U/ml)", value=0.0)
    input_data["M11"] = st.number_input("Body Mass Index (BMI)", value=0.0)
    input_data["BD2"] = st.number_input("Diabetes Pedigree Function (mu U/ml)", value=0.0)
    input_data["Age"] = st.slider("Age of the patient (years)", 0, 100, 0)

# Predict Button with Style
if st.button("🔮 Predict Sepsis"):
    try:
        input_data_scaled_df = preprocess_input_data(input_data)
        sepsis_status = make_predictions(input_data_scaled_df)
        st.success(f"The predicted sepsis status is: {sepsis_status}")
    except Exception as e:
        st.error(f"An error occurred: {e}")

# Display Data Fields and Descriptions
st.sidebar.title("🔍 Data Fields")
for field, description in data_fields.items():
    st.sidebar.text(f"{field}: {description}")