Update app.py
Browse files
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 |
-
#
|
446 |
-
|
447 |
-
|
|
|
448 |
|
449 |
-
#
|
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
|
468 |
-
formatted_text += f"**High activation**:\n{
|
469 |
-
if
|
470 |
-
formatted_text += f"**Moderate activation**:\n{
|
471 |
-
if
|
472 |
-
formatted_text += f"**Low activation**:\n{
|
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 |
|