hmgill commited on
Commit
61e6e27
Β·
verified Β·
1 Parent(s): d22d999

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -73,6 +73,10 @@ def process_image_task(image_path: str, task_text: str, agent: CellposeAgent) ->
73
  """
74
  Process a user task with the CellposeAgent.
75
 
 
 
 
 
76
  Args:
77
  image_path: Path to the uploaded image file
78
  task_text: User's text prompt/question
@@ -84,25 +88,18 @@ def process_image_task(image_path: str, task_text: str, agent: CellposeAgent) ->
84
  if not image_path:
85
  return "⚠️ Please upload an image first.", None
86
 
87
- # Store the actual image path in agent context/memory BEFORE running
88
- # This ensures the agent has access to the correct path
89
- #agent.agent.memory.clear() # Optional: clear previous context
90
-
91
- # Build task with clear, unambiguous path format
92
  if not task_text or task_text.strip() == "":
93
- # Use a more explicit format that's harder for LLM to corrupt
94
- task = f"""Analyze the image at this exact path: `{image_path}`
95
- What parameters would work best for this image?"""
96
  else:
97
- if image_path not in task_text:
98
- task = f"""Image path: `{image_path}`
99
- Task: {task_text}"""
100
- else:
101
- task = task_text
102
-
103
 
104
  try:
105
- result = agent.run(task)
 
 
106
  get_client().flush()
107
 
108
  # Extract output image path from agent's memory (more reliable than parsing text)
@@ -171,7 +168,7 @@ def create_gradio_interface():
171
  # Task input
172
  task_input = gr.Textbox(
173
  label="Task / Question",
174
- placeholder="e.g., 'What parameters would work best?' or 'Run segmentation' (image path added automatically)",
175
  lines=3
176
  )
177
 
@@ -233,6 +230,11 @@ def create_gradio_interface():
233
  4. Runs segmentation and checks quality
234
  5. Refines parameters if needed (up to 2 iterations)
235
  6. **Displays the segmented overlay image with colored cell masks**
 
 
 
 
 
236
  """
237
  )
238
 
 
73
  """
74
  Process a user task with the CellposeAgent.
75
 
76
+ The image_path is now passed SEPARATELY to agent.run() so it gets stored
77
+ in global context. This prevents the LLM from needing to reproduce the
78
+ exact path string (which it often corrupts).
79
+
80
  Args:
81
  image_path: Path to the uploaded image file
82
  task_text: User's text prompt/question
 
88
  if not image_path:
89
  return "⚠️ Please upload an image first.", None
90
 
91
+ # Build task WITHOUT embedding the full path
92
+ # The agent instructions tell it to use image_path="" and the tool will resolve from context
 
 
 
93
  if not task_text or task_text.strip() == "":
94
+ task = "Analyze the uploaded image and recommend optimal segmentation parameters. Then run segmentation."
 
 
95
  else:
96
+ # Don't include the path in the task - it will be available via context
97
+ task = task_text
 
 
 
 
98
 
99
  try:
100
+ # Pass image_path SEPARATELY - this stores it in global context
101
+ # Tools will retrieve the correct path from context instead of relying on LLM
102
+ result = agent.run(task=task, image_path=image_path)
103
  get_client().flush()
104
 
105
  # Extract output image path from agent's memory (more reliable than parsing text)
 
168
  # Task input
169
  task_input = gr.Textbox(
170
  label="Task / Question",
171
+ placeholder="e.g., 'What parameters would work best?' or 'Run segmentation' (image path handled automatically)",
172
  lines=3
173
  )
174
 
 
230
  4. Runs segmentation and checks quality
231
  5. Refines parameters if needed (up to 2 iterations)
232
  6. **Displays the segmented overlay image with colored cell masks**
233
+
234
+ ### βš™οΈ Technical Note
235
+
236
+ Image paths are handled automatically by the system - the agent doesn't need to
237
+ reproduce exact file paths, preventing common path corruption issues with LLMs.
238
  """
239
  )
240