cvips commited on
Commit
4fa08fd
·
1 Parent(s): bdb6d79

biomedparse+biomedllama_3b_multimodal

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -382,14 +382,18 @@ def process_image(image_path, user_prompt, modality=None):
382
 
383
  # Add color mapping to analysis with more natural language
384
  color_descriptions = []
 
 
385
  for idx, prompt in enumerate(relevant_prompts):
386
  if prompt in detailed_analysis.lower():
387
  color = colors[idx % len(colors)]
388
  color_name = {(255,0,0): "red", (0,255,0): "green", (0,0,255): "blue",
389
  (255,255,0): "yellow", (255,0,255): "magenta"}[color]
390
  color_descriptions.append(f"The {prompt} is highlighted in {color_name} color")
 
391
 
392
- for idx, prompt in enumerate(relevant_prompts):
 
393
  try:
394
  mask_list = interactive_infer_image(model, pil_image, [prompt])
395
  if mask_list is None or len(mask_list) == 0:
@@ -413,7 +417,7 @@ def process_image(image_path, user_prompt, modality=None):
413
  analysis_results.append(f"Failed to process '{prompt}': {str(e)}")
414
 
415
  if not results:
416
- results = [image] # Return original image if no overlays were created
417
  detailed_analysis += "\n\nIn the segmentation analysis:"
418
  if color_descriptions:
419
  detailed_analysis += " " + " ".join(color_descriptions) + "."
 
382
 
383
  # Add color mapping to analysis with more natural language
384
  color_descriptions = []
385
+ # First loop: collect prompts found in the analysis
386
+ found_prompts = []
387
  for idx, prompt in enumerate(relevant_prompts):
388
  if prompt in detailed_analysis.lower():
389
  color = colors[idx % len(colors)]
390
  color_name = {(255,0,0): "red", (0,255,0): "green", (0,0,255): "blue",
391
  (255,255,0): "yellow", (255,0,255): "magenta"}[color]
392
  color_descriptions.append(f"The {prompt} is highlighted in {color_name} color")
393
+ found_prompts.append(prompt)
394
 
395
+ # Second loop: only process prompts found in analysis
396
+ for idx, prompt in enumerate(found_prompts):
397
  try:
398
  mask_list = interactive_infer_image(model, pil_image, [prompt])
399
  if mask_list is None or len(mask_list) == 0:
 
417
  analysis_results.append(f"Failed to process '{prompt}': {str(e)}")
418
 
419
  if not results:
420
+ results = [image] # Return original image if no overlays were created
421
  detailed_analysis += "\n\nIn the segmentation analysis:"
422
  if color_descriptions:
423
  detailed_analysis += " " + " ".join(color_descriptions) + "."