Update app.py
Browse files
app.py
CHANGED
|
@@ -441,14 +441,25 @@ def generate_gradcam_caption(image, processor, model, max_length=60):
|
|
| 441 |
# Decode the output
|
| 442 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
| 443 |
|
| 444 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
structured_output = f"""
|
| 446 |
-
**Heatmap Analysis**:
|
|
|
|
|
|
|
| 447 |
|
| 448 |
-
**
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
"""
|
| 453 |
return structured_output.strip()
|
| 454 |
|
|
@@ -764,14 +775,15 @@ def main():
|
|
| 764 |
# Image Analysis Summary section - AFTER Stage 2
|
| 765 |
if hasattr(st.session_state, 'current_image') and (hasattr(st.session_state, 'image_caption') or hasattr(st.session_state, 'gradcam_caption')):
|
| 766 |
with st.expander("Image Analysis Summary", expanded=True):
|
| 767 |
-
# Display
|
| 768 |
col1, col2 = st.columns([1, 2])
|
| 769 |
|
| 770 |
with col1:
|
| 771 |
-
# Display original image
|
| 772 |
st.image(st.session_state.current_image, caption="Original Image", width=300)
|
| 773 |
-
#
|
| 774 |
-
|
|
|
|
| 775 |
|
| 776 |
with col2:
|
| 777 |
# Image description
|
|
|
|
| 441 |
# Decode the output
|
| 442 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
| 443 |
|
| 444 |
+
# Split the caption into activation levels
|
| 445 |
+
caption_parts = caption.split("activation")
|
| 446 |
+
formatted_parts = []
|
| 447 |
+
|
| 448 |
+
for part in caption_parts[1:]: # Skip the first empty part
|
| 449 |
+
if ":" in part:
|
| 450 |
+
level, description = part.split(":", 1)
|
| 451 |
+
formatted_parts.append(f"**{level.strip()} activation**:{description.strip()}")
|
| 452 |
+
|
| 453 |
+
# Format into structured analysis with better spacing
|
| 454 |
structured_output = f"""
|
| 455 |
+
**Heatmap Analysis**:
|
| 456 |
+
|
| 457 |
+
{chr(10).join(formatted_parts)}
|
| 458 |
|
| 459 |
+
**Legend**:
|
| 460 |
+
🔴 Red/Yellow = High importance regions
|
| 461 |
+
🟡 Green/Cyan = Medium importance regions
|
| 462 |
+
🔵 Blue/Dark = Low importance regions
|
| 463 |
"""
|
| 464 |
return structured_output.strip()
|
| 465 |
|
|
|
|
| 775 |
# Image Analysis Summary section - AFTER Stage 2
|
| 776 |
if hasattr(st.session_state, 'current_image') and (hasattr(st.session_state, 'image_caption') or hasattr(st.session_state, 'gradcam_caption')):
|
| 777 |
with st.expander("Image Analysis Summary", expanded=True):
|
| 778 |
+
# Display images and analysis in organized layout
|
| 779 |
col1, col2 = st.columns([1, 2])
|
| 780 |
|
| 781 |
with col1:
|
| 782 |
+
# Display original image
|
| 783 |
st.image(st.session_state.current_image, caption="Original Image", width=300)
|
| 784 |
+
# Display GradCAM overlay
|
| 785 |
+
if hasattr(st.session_state, 'current_overlay'):
|
| 786 |
+
st.image(st.session_state.current_overlay, caption="GradCAM Visualization", width=300)
|
| 787 |
|
| 788 |
with col2:
|
| 789 |
# Image description
|