rasmodev commited on
Commit
8aadd07
·
1 Parent(s): d7daaeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -39
app.py CHANGED
@@ -135,47 +135,26 @@ if st.button("🔮 Predict Sepsis"):
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
 
 
135
  # Convert the input data to a pandas DataFrame
136
  input_df = pd.DataFrame([input_data])
137
 
138
+ # Display the DataFrame
139
  st.table(input_df)
140
 
141
+ # Download Button Section
142
+ st.subheader("Download Prediction")
143
+ patient_name = st.text_input("Enter the patient's name:")
144
+ if st.button("Download Prediction"):
145
+ if patient_name:
146
+ # Generate the heading
147
+ heading = f"Sepsis Status Prediction For {patient_name}"
148
+
149
+ # Save the DataFrame to a CSV file
150
+ input_df.to_csv(f"{patient_name}_sepsis_prediction.csv", index=False, encoding='utf-8-sig')
151
+
152
+ # Provide a download link
153
+ st.markdown(f"### [Download {patient_name}'s Prediction CSV](data:{patient_name}_sepsis_prediction.csv)")
154
+
155
+ else:
156
+ st.warning("Please enter the patient's name.")
157
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  except Exception as e:
159
  st.error(f"An error occurred: {e}")
160