Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import streamlit as st
|
|
| 2 |
import pickle
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Page Title with Style
|
| 7 |
# st.title("🩸 Sepsis Prediction App")
|
|
@@ -126,10 +128,54 @@ if st.button("🔮 Predict Sepsis"):
|
|
| 126 |
input_data_scaled_df = preprocess_input_data(input_data)
|
| 127 |
sepsis_status = make_predictions(input_data_scaled_df)
|
| 128 |
st.success(f"The predicted sepsis status is: {sepsis_status}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# Convert the input data to a pandas DataFrame
|
| 130 |
input_df = pd.DataFrame([input_data])
|
|
|
|
|
|
|
| 131 |
st.table(input_df)
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
st.error(f"An error occurred: {e}")
|
| 135 |
|
|
|
|
| 2 |
import pickle
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from reportlab.pdfgen import canvas
|
| 7 |
|
| 8 |
# Page Title with Style
|
| 9 |
# st.title("🩸 Sepsis Prediction App")
|
|
|
|
| 128 |
input_data_scaled_df = preprocess_input_data(input_data)
|
| 129 |
sepsis_status = make_predictions(input_data_scaled_df)
|
| 130 |
st.success(f"The predicted sepsis status is: {sepsis_status}")
|
| 131 |
+
|
| 132 |
+
# Add the sepsis prediction to the input DataFrame
|
| 133 |
+
input_data['Sepsis'] = sepsis_status
|
| 134 |
+
|
| 135 |
# Convert the input data to a pandas DataFrame
|
| 136 |
input_df = pd.DataFrame([input_data])
|
| 137 |
+
|
| 138 |
+
# Display DataFrame
|
| 139 |
st.table(input_df)
|
| 140 |
+
|
| 141 |
+
# Download Button
|
| 142 |
+
download_btn = st.button("📥 Download Prediction")
|
| 143 |
+
|
| 144 |
+
if download_btn:
|
| 145 |
+
# Prompt user for patient's name
|
| 146 |
+
patient_name = st.text_input("Enter Patient's Name:")
|
| 147 |
+
|
| 148 |
+
# Create heading
|
| 149 |
+
heading = f"Sepsis Status Prediction For {patient_name}"
|
| 150 |
+
|
| 151 |
+
# Export to Excel
|
| 152 |
+
excel_file = BytesIO()
|
| 153 |
+
with pd.ExcelWriter(excel_file, engine='openpyxl') as writer:
|
| 154 |
+
input_df.to_excel(writer, sheet_name='Sheet1', index=False)
|
| 155 |
+
writer.sheets['Sheet1'].title = heading
|
| 156 |
+
excel_file.seek(0)
|
| 157 |
+
st.download_button(
|
| 158 |
+
label="Download Excel",
|
| 159 |
+
data=excel_file,
|
| 160 |
+
file_name=f"sepsis_prediction_{patient_name}.xlsx",
|
| 161 |
+
key='excel-download',
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
# Export to PDF
|
| 165 |
+
pdf_file = BytesIO()
|
| 166 |
+
pdf_canvas = canvas.Canvas(pdf_file)
|
| 167 |
+
pdf_canvas.drawString(100, 800, heading)
|
| 168 |
+
table = input_df.to_string().split('\n')
|
| 169 |
+
pdf_canvas.drawString(100, 780, '\n'.join(table))
|
| 170 |
+
pdf_canvas.save()
|
| 171 |
+
pdf_file.seek(0)
|
| 172 |
+
st.download_button(
|
| 173 |
+
label="Download PDF",
|
| 174 |
+
data=pdf_file,
|
| 175 |
+
file_name=f"sepsis_prediction_{patient_name}.pdf",
|
| 176 |
+
key='pdf-download',
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
except Exception as e:
|
| 180 |
st.error(f"An error occurred: {e}")
|
| 181 |
|