saakshigupta commited on
Commit
4692daa
·
verified ·
1 Parent(s): d88f984

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -26
app.py CHANGED
@@ -442,34 +442,19 @@ def generate_gradcam_caption(image, processor, model, max_length=60):
442
  # Decode the output
443
  caption = processor.decode(output[0], skip_special_tokens=True)
444
 
445
- # Clean and format the text
446
- # First, split by activation levels
447
- text_parts = caption.lower().split("activation")
 
448
 
449
- # Initialize empty strings for each activation level
450
- high_text = ""
451
- moderate_text = ""
452
- low_text = ""
453
-
454
- # Process each part
455
- for part in text_parts:
456
- if not part.strip(): # Skip empty parts
457
- continue
458
- if "high" in part:
459
- high_text = part.split(":", 1)[1].strip() if ":" in part else part.strip()
460
- elif "moderate" in part:
461
- moderate_text = part.split(":", 1)[1].strip() if ":" in part else part.strip()
462
- elif "low" in part:
463
- low_text = part.split(":", 1)[1].strip() if ":" in part else part.strip()
464
-
465
- # Format the output with only the unique content for each level
466
  formatted_text = ""
467
- if high_text:
468
- formatted_text += f"**High activation**:\n{high_text}\n\n"
469
- if moderate_text:
470
- formatted_text += f"**Moderate activation**:\n{moderate_text}\n\n"
471
- if low_text:
472
- formatted_text += f"**Low activation**:\n{low_text}"
473
 
474
  return formatted_text.strip()
475
 
 
442
  # Decode the output
443
  caption = processor.decode(output[0], skip_special_tokens=True)
444
 
445
+ # Extract descriptions using the full text
446
+ high_match = caption.split("high activation :")[1].split("moderate")[0] if "high activation :" in caption else ""
447
+ moderate_match = caption.split("moderate activation :")[1].split("low")[0] if "moderate activation :" in caption else ""
448
+ low_match = caption.split("low activation :")[1] if "low activation :" in caption else ""
449
 
450
+ # Format the output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  formatted_text = ""
452
+ if high_match:
453
+ formatted_text += f"**High activation**:\n{high_match.strip()}\n\n"
454
+ if moderate_match:
455
+ formatted_text += f"**Moderate activation**:\n{moderate_match.strip()}\n\n"
456
+ if low_match:
457
+ formatted_text += f"**Low activation**:\n{low_match.strip()}"
458
 
459
  return formatted_text.strip()
460