luigi12345 commited on
Commit
8a1d3d2
β€’
1 Parent(s): 74d3d9b
Files changed (1) hide show
  1. app.py +50 -72
app.py CHANGED
@@ -183,61 +183,38 @@ def save_results(results, original_images):
183
  def main():
184
  st.set_page_config(layout="wide", page_title="Glaucoma Screening Tool")
185
 
186
- print("Starting app...") # Debug print
187
-
188
  st.markdown("""
189
  <h1 style='text-align: center;'>Glaucoma Screening from Retinal Fundus Images</h1>
190
  <p style='text-align: center; color: gray;'>Upload retinal images for automated glaucoma detection and optic disc/cup segmentation</p>
191
  """, unsafe_allow_html=True)
192
 
193
- print("Header rendered...") # Debug print
 
 
 
 
 
 
 
194
 
195
- # Add session state for better state management
196
- if 'processed_count' not in st.session_state:
197
- st.session_state.processed_count = 0
198
-
199
- # Add a more informative sidebar
200
- with st.sidebar:
201
- st.markdown("### πŸ“€ Upload Images")
202
- uploaded_files = st.file_uploader(
203
- "Upload Retinal Images",
204
- type=['png', 'jpeg', 'jpg'],
205
- accept_multiple_files=True,
206
- help="Support multiple images in PNG, JPEG formats"
207
- )
208
-
209
- st.markdown("### πŸ“Š Processing Stats")
210
- if 'processed_count' in st.session_state:
211
- # Replace st.metric with regular markdown
212
- st.markdown(f"**Images Processed:** {st.session_state.processed_count}")
213
-
214
- st.markdown("---")
215
-
216
- # Add batch size limit
217
- max_batch = st.number_input("Max Batch Size",
218
- min_value=1,
219
- max_value=100,
220
- value=20,
221
- help="Maximum number of images to process in one batch")
222
 
223
  if uploaded_files:
224
- # Validate batch size
225
  if len(uploaded_files) > max_batch:
226
- st.warning(f"⚠️ Please upload maximum {max_batch} images at once. Current: {len(uploaded_files)}")
227
  return
228
 
229
- # Add loading animation
230
- with st.spinner('πŸ”„ Initializing model...'):
231
- model = GlaucomaModel(device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu"))
232
 
233
- # Add summary metrics at the top
234
- col1, col2 = st.columns(2)
235
- with col1:
236
- st.info(f"πŸ“ Total images: {len(uploaded_files)}")
237
- with col2:
238
- st.info(f"βš™οΈ Using: {'GPU' if torch.cuda.is_available() else 'CPU'}")
239
 
240
- # Prepare images data
241
  images_data = []
242
  original_images = []
243
  for file in uploaded_files:
@@ -250,43 +227,44 @@ def main():
250
  st.error(f"Error loading {file.name}: {str(e)}")
251
  continue
252
 
253
- progress_bar = st.progress(0)
254
  st.write(f"Processing {len(images_data)} images...")
255
 
256
  # Process all images
257
- results = process_batch(model, images_data, progress_bar)
258
 
259
  if results:
260
- # Generate ZIP with results
 
 
 
 
 
 
 
 
 
 
 
 
261
  zip_data = save_results(results, original_images)
262
 
263
- # Add export options
264
- st.markdown("### πŸ“₯ Export Options")
265
- col1, col2 = st.columns(2)
266
- with col1:
267
- st.download_button(
268
- label="πŸ“₯ Download All Results (ZIP)",
269
- data=zip_data, # Now zip_data is properly defined
270
- file_name=f"glaucoma_screening_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip",
271
- mime="application/zip"
272
- )
273
- with col2:
274
- # Add CSV-only download
275
- csv_data = pd.DataFrame([{
276
- 'File': r['file_name'],
277
- 'Diagnosis': r['diagnosis'],
278
- 'Confidence': r['confidence'],
279
- 'VCDR': r['vcdr']
280
- } for r in results]).to_csv(index=False)
281
-
282
- st.download_button(
283
- label="πŸ“Š Download Report (CSV)",
284
- data=csv_data,
285
- file_name=f"glaucoma_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv",
286
- mime="text/csv"
287
- )
288
 
289
- # Add this at the end of the file
290
  if __name__ == "__main__":
291
- print("Running main...") # Debug print
292
  main()
 
183
  def main():
184
  st.set_page_config(layout="wide", page_title="Glaucoma Screening Tool")
185
 
 
 
186
  st.markdown("""
187
  <h1 style='text-align: center;'>Glaucoma Screening from Retinal Fundus Images</h1>
188
  <p style='text-align: center; color: gray;'>Upload retinal images for automated glaucoma detection and optic disc/cup segmentation</p>
189
  """, unsafe_allow_html=True)
190
 
191
+ # Simple sidebar without columns
192
+ st.sidebar.markdown("### πŸ“€ Upload Images")
193
+ uploaded_files = st.sidebar.file_uploader(
194
+ "Upload Retinal Images",
195
+ type=['png', 'jpeg', 'jpg'],
196
+ accept_multiple_files=True,
197
+ help="Support multiple images in PNG, JPEG formats"
198
+ )
199
 
200
+ st.sidebar.markdown("### Settings")
201
+ max_batch = st.sidebar.number_input("Max Batch Size",
202
+ min_value=1,
203
+ max_value=100,
204
+ value=20)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  if uploaded_files:
 
207
  if len(uploaded_files) > max_batch:
208
+ st.warning(f"Please upload maximum {max_batch} images at once.")
209
  return
210
 
211
+ st.markdown(f"Total images: {len(uploaded_files)}")
212
+ st.markdown(f"Using: {'GPU' if torch.cuda.is_available() else 'CPU'}")
 
213
 
214
+ # Initialize model
215
+ model = GlaucomaModel(device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu"))
 
 
 
 
216
 
217
+ # Process images
218
  images_data = []
219
  original_images = []
220
  for file in uploaded_files:
 
227
  st.error(f"Error loading {file.name}: {str(e)}")
228
  continue
229
 
230
+ progress = st.progress(0)
231
  st.write(f"Processing {len(images_data)} images...")
232
 
233
  # Process all images
234
+ results = process_batch(model, images_data, progress)
235
 
236
  if results:
237
+ # Show results one by one
238
+ for result in results:
239
+ st.markdown(f"### Results for {result['file_name']}")
240
+ st.markdown(f"**Diagnosis:** {result['diagnosis']}")
241
+ st.markdown(f"**Confidence:** {result['confidence']:.1f}%")
242
+ st.markdown(f"**VCDR:** {result['vcdr']:.3f}")
243
+
244
+ # Display images
245
+ st.image(result['processed_image'], caption="Segmentation")
246
+ st.image(result['cropped_image'], caption="ROI")
247
+ st.markdown("---")
248
+
249
+ # Generate downloads
250
  zip_data = save_results(results, original_images)
251
 
252
+ st.markdown("### Download Results")
253
+ st.download_button(
254
+ label="Download All Results (ZIP)",
255
+ data=zip_data,
256
+ file_name=f"glaucoma_screening_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip",
257
+ mime="application/zip"
258
+ )
259
+
260
+ # Simple summary
261
+ st.markdown("### Summary")
262
+ glaucoma_count = sum(1 for r in results if r['diagnosis'] == 'Glaucoma')
263
+ normal_count = len(results) - glaucoma_count
264
+ st.markdown(f"**Total Processed:** {len(results)}")
265
+ st.markdown(f"**Glaucoma Detected:** {glaucoma_count}")
266
+ st.markdown(f"**Normal:** {normal_count}")
267
+ st.markdown(f"**Average Confidence:** {sum(r['confidence'] for r in results) / len(results):.1f}%")
 
 
 
 
 
 
 
 
 
268
 
 
269
  if __name__ == "__main__":
 
270
  main()