samwell Claude commited on
Commit
d2991ca
·
1 Parent(s): 85e170b

fix: Handle empty assistant responses when visualizations are generated

Browse files

When segmentation/grounding tools run, Gemini sometimes returns empty
responses, causing blank chat bubbles in the UI.

Solution: Provide helpful default messages when:
- Segmentation visualization is created
- Grounding visualization is created
- Any other empty response occurs

This ensures users always see a message explaining what happened.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -254,6 +254,17 @@ def chat(message, history, mode):
254
  if os.path.exists(latest_viz):
255
  viz_image = latest_viz
256
 
 
 
 
 
 
 
 
 
 
 
 
257
  return assistant_message, viz_image
258
 
259
  # Custom interface with image output
 
254
  if os.path.exists(latest_viz):
255
  viz_image = latest_viz
256
 
257
+ # If assistant message is empty but we have a visualization, provide a default message
258
+ if not assistant_message or assistant_message.strip() == "":
259
+ if "segmentation" in latest_viz:
260
+ assistant_message = "I've segmented the requested anatomical structures. The visualization is shown on the right."
261
+ elif "grounding" in latest_viz:
262
+ assistant_message = "I've highlighted the requested regions. The visualization is shown on the right."
263
+
264
+ # Final fallback for empty messages
265
+ if not assistant_message or assistant_message.strip() == "":
266
+ assistant_message = "I processed your request. Please check the visualization panel on the right."
267
+
268
  return assistant_message, viz_image
269
 
270
  # Custom interface with image output