Spaces:
Sleeping
Sleeping
feat: Display uploaded X-ray image as reference before visualization
Browse filesWhen users upload an X-ray image, immediately display it in the
visualization panel as a reference. Once segmentation or grounding
is complete, the visualization replaces the original image.
Flow:
1. User uploads X-ray → Shows original image on right
2. User requests segmentation → Original image visible as reference
3. Segmentation completes → Overlay replaces original image
This provides visual context while the agent processes the request.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -160,7 +160,7 @@ def get_or_create_agent(mode):
|
|
| 160 |
)
|
| 161 |
return agents_cache[mode]
|
| 162 |
|
| 163 |
-
def chat(message, history, mode):
|
| 164 |
"""Chat function that uses the appropriate agent based on mode."""
|
| 165 |
config = {"configurable": {"thread_id": f"thread_{mode}"}}
|
| 166 |
|
|
@@ -169,12 +169,14 @@ def chat(message, history, mode):
|
|
| 169 |
|
| 170 |
# Handle multimodal input - Gemini 2.0 Flash supports vision
|
| 171 |
image_content = None
|
|
|
|
| 172 |
if isinstance(message, dict):
|
| 173 |
text = message.get("text", "")
|
| 174 |
files = message.get("files", [])
|
| 175 |
|
| 176 |
if files and len(files) > 0:
|
| 177 |
image_path = files[0]
|
|
|
|
| 178 |
|
| 179 |
# Check if it's a DICOM file
|
| 180 |
is_dicom = image_path.lower().endswith(('.dcm', '.dicom'))
|
|
@@ -260,6 +262,10 @@ def chat(message, history, mode):
|
|
| 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() == "":
|
|
|
|
| 160 |
)
|
| 161 |
return agents_cache[mode]
|
| 162 |
|
| 163 |
+
def chat(message, history, mode, uploaded_image_path=None):
|
| 164 |
"""Chat function that uses the appropriate agent based on mode."""
|
| 165 |
config = {"configurable": {"thread_id": f"thread_{mode}"}}
|
| 166 |
|
|
|
|
| 169 |
|
| 170 |
# Handle multimodal input - Gemini 2.0 Flash supports vision
|
| 171 |
image_content = None
|
| 172 |
+
current_upload = None # Track the current uploaded image
|
| 173 |
if isinstance(message, dict):
|
| 174 |
text = message.get("text", "")
|
| 175 |
files = message.get("files", [])
|
| 176 |
|
| 177 |
if files and len(files) > 0:
|
| 178 |
image_path = files[0]
|
| 179 |
+
current_upload = image_path # Store for visualization
|
| 180 |
|
| 181 |
# Check if it's a DICOM file
|
| 182 |
is_dicom = image_path.lower().endswith(('.dcm', '.dicom'))
|
|
|
|
| 262 |
assistant_message = "I've segmented the requested anatomical structures. The visualization is shown on the right."
|
| 263 |
elif "grounding" in latest_viz:
|
| 264 |
assistant_message = "I've highlighted the requested regions. The visualization is shown on the right."
|
| 265 |
+
else:
|
| 266 |
+
# No visualization generated - show the uploaded image as reference
|
| 267 |
+
if current_upload:
|
| 268 |
+
viz_image = current_upload
|
| 269 |
|
| 270 |
# Final fallback for empty messages
|
| 271 |
if not assistant_message or assistant_message.strip() == "":
|