| import streamlit as st |
| import pickle |
| import pandas as pd |
| import numpy as np |
|
|
| |
| |
| |
| st.markdown( |
| f""" |
| <div style="text-align: center;"> |
| <h1 style="color: #800000;">🩸 Sepsis Prediction App</h1> |
| </div> |
| """, |
| unsafe_allow_html=True |
| ) |
| st.markdown("---") |
|
|
| |
| 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." |
| ) |
|
|
| |
| 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." |
| ) |
|
|
| |
| 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 = { |
| "PRG": "Number of Pregnancies (applicable only to females)\n - The total number of pregnancies a female patient has experienced.", |
| "PL": "Plasma Glucose Concentration (mg/dL)\n - The concentration of glucose in the patient's blood). It provides insights into the patient's blood sugar levels.", |
| "PR": "Diastolic Blood Pressure (mm Hg)\n - The diastolic blood pressure, representing the pressure in the arteries when the heart is at rest between beats.", |
| "SK": "Triceps Skinfold Thickness (mm)\n - The thickness of the skinfold on the triceps, measured in millimeters (mm). This measurement is often used to assess body fat percentage.", |
| "TS": "2-hour Serum Insulin (mu U/ml)\n - The level of insulin in the patient's blood two hours after a meal, measured in micro international units per milliliter (mu U/ml).", |
| "M11": "Body Mass Index (BMI) (weight in kg / {(height in m)}^2)\n - BMI provides a standardized measure that helps assess the degree of body fat and categorizes individuals into different weight status categories, such as underweight, normal weight, overweight, and obesity.", |
| "BD2": "Diabetes pedigree function (mu U/ml)\n - The function provides information about the patient's family history of diabetes.", |
| "Age": "Age of the Patient (years)\n - Age is an essential factor in medical assessments and can influence various health outcomes." |
| } |
| |
| col1, col2 = st.columns(2) |
|
|
| |
| 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) |
|
|
| |
| 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]] |
|
|
| |
| 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) |
|
|
| |
| 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}") |
|
|
| |
| st.sidebar.title("🔍 Data Fields") |
| for field, description in data_fields.items(): |
| st.sidebar.markdown(f"{field}: {description}") |