luigi12345
commited on
Commit
β’
8a1d3d2
1
Parent(s):
74d3d9b
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
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"
|
227 |
return
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
model = GlaucomaModel(device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu"))
|
232 |
|
233 |
-
#
|
234 |
-
|
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 |
-
#
|
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 |
-
|
254 |
st.write(f"Processing {len(images_data)} images...")
|
255 |
|
256 |
# Process all images
|
257 |
-
results = process_batch(model, images_data,
|
258 |
|
259 |
if results:
|
260 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
zip_data = save_results(results, original_images)
|
262 |
|
263 |
-
|
264 |
-
st.
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
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()
|