luigi12345
commited on
Commit
•
56a1577
1
Parent(s):
27efa08
app.py
CHANGED
@@ -102,16 +102,17 @@ def add_mask(image, mask, classes, colors, alpha=0.5):
|
|
102 |
return output, overlay
|
103 |
|
104 |
def get_confidence_level(confidence):
|
|
|
105 |
if confidence >= 90:
|
106 |
-
return "Very
|
107 |
elif confidence >= 75:
|
108 |
-
return "
|
109 |
elif confidence >= 60:
|
110 |
-
return "
|
111 |
elif confidence >= 45:
|
112 |
-
return "
|
113 |
else:
|
114 |
-
return "Very
|
115 |
|
116 |
def process_batch(model, images_data, progress_bar=None):
|
117 |
results = []
|
@@ -222,21 +223,43 @@ def main():
|
|
222 |
# Get predictions
|
223 |
disease_idx, disc_cup_image, vcdr, cls_conf, cup_conf, disc_conf, cropped_image = model.process(image_np)
|
224 |
|
225 |
-
#
|
226 |
st.write("---")
|
227 |
st.write(f"Results for {file.name}")
|
228 |
|
229 |
-
#
|
230 |
-
|
231 |
-
st.write(f"
|
232 |
-
st.write(f"Confidence: {cls_conf:.1f}%")
|
233 |
-
st.write(f"VCDR: {vcdr:.3f}")
|
234 |
|
235 |
-
#
|
236 |
-
st.write("Segmentation
|
237 |
-
st.
|
238 |
-
st.write("
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
except Exception as e:
|
242 |
st.error(f"Error processing {file.name}: {str(e)}")
|
|
|
102 |
return output, overlay
|
103 |
|
104 |
def get_confidence_level(confidence):
|
105 |
+
"""Enhanced confidence descriptions for segmentation"""
|
106 |
if confidence >= 90:
|
107 |
+
return "Excellent (Very clear boundaries)"
|
108 |
elif confidence >= 75:
|
109 |
+
return "Good (Clear boundaries)"
|
110 |
elif confidence >= 60:
|
111 |
+
return "Fair (Visible but some unclear areas)"
|
112 |
elif confidence >= 45:
|
113 |
+
return "Poor (Difficult to determine)"
|
114 |
else:
|
115 |
+
return "Very Poor (Not reliable)"
|
116 |
|
117 |
def process_batch(model, images_data, progress_bar=None):
|
118 |
results = []
|
|
|
223 |
# Get predictions
|
224 |
disease_idx, disc_cup_image, vcdr, cls_conf, cup_conf, disc_conf, cropped_image = model.process(image_np)
|
225 |
|
226 |
+
# Enhanced results display
|
227 |
st.write("---")
|
228 |
st.write(f"Results for {file.name}")
|
229 |
|
230 |
+
# Diagnosis section
|
231 |
+
st.write("📊 **Diagnosis Results:**")
|
232 |
+
st.write(f"• Finding: {model.cls_id2label[disease_idx]}")
|
233 |
+
st.write(f"• AI Confidence: {cls_conf:.1f}% ({get_confidence_level(cls_conf)})")
|
|
|
234 |
|
235 |
+
# Segmentation confidence section
|
236 |
+
st.write("\n🔍 **Segmentation Quality:**")
|
237 |
+
st.write(f"• Optic Cup Detection: {cup_conf:.1f}% - {get_confidence_level(cup_conf)}")
|
238 |
+
st.write(f"• Optic Disc Detection: {disc_conf:.1f}% - {get_confidence_level(disc_conf)}")
|
239 |
+
|
240 |
+
# Clinical metrics
|
241 |
+
st.write("\n📏 **Clinical Measurements:**")
|
242 |
+
st.write(f"• Cup-to-Disc Ratio (VCDR): {vcdr:.3f}")
|
243 |
+
if vcdr > 0.7:
|
244 |
+
st.write(" ⚠️ High VCDR - Potential risk indicator")
|
245 |
+
elif vcdr > 0.5:
|
246 |
+
st.write(" ℹ️ Borderline VCDR - Follow-up recommended")
|
247 |
+
else:
|
248 |
+
st.write(" ✅ Normal VCDR range")
|
249 |
+
|
250 |
+
# Image display with enhanced captions
|
251 |
+
st.write("\n🖼️ **Visual Analysis:**")
|
252 |
+
st.image(disc_cup_image, caption="""
|
253 |
+
Segmentation Overlay
|
254 |
+
• Green outline: Optic Disc boundary
|
255 |
+
• Red area: Optic Cup region
|
256 |
+
• Transparency shows underlying retina
|
257 |
+
""")
|
258 |
+
st.image(cropped_image, caption="Zoomed Region of Interest")
|
259 |
+
|
260 |
+
# Add quality note if needed
|
261 |
+
if cup_conf < 60 or disc_conf < 60:
|
262 |
+
st.write("\n⚠️ Note: Low segmentation confidence. Image quality might affect measurements.")
|
263 |
|
264 |
except Exception as e:
|
265 |
st.error(f"Error processing {file.name}: {str(e)}")
|