saakshigupta commited on
Commit
9e95b93
·
verified ·
1 Parent(s): b1cacf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
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
- # Format into structured analysis
 
 
 
 
 
 
 
 
 
445
  structured_output = f"""
446
- **Heatmap Analysis**: {caption}
 
 
447
 
448
- **Key Observations**:
449
- - The red/yellow regions indicate areas of high importance in the detection process
450
- - The green/cyan areas show regions of medium importance
451
- - The blue/dark blue regions represent features with lower impact on the model's decision
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 image, captions, and results in organized layout with proper formatting
768
  col1, col2 = st.columns([1, 2])
769
 
770
  with col1:
771
- # Display original image and overlay side by side with controlled size
772
  st.image(st.session_state.current_image, caption="Original Image", width=300)
773
- # if hasattr(st.session_state, 'current_overlay'):
774
- # st.image(st.session_state.current_overlay, caption="GradCAM Overlay", width=300)
 
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