Update app.py
Browse files
app.py
CHANGED
@@ -442,33 +442,39 @@ 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 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
468 |
|
469 |
except Exception as e:
|
470 |
st.error(f"Error analyzing GradCAM: {str(e)}")
|
471 |
-
st.write("Debug - Full error:", str(e))
|
472 |
return "Error analyzing GradCAM visualization"
|
473 |
|
474 |
# Function to generate caption for original image
|
|
|
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 |
|
476 |
except Exception as e:
|
477 |
st.error(f"Error analyzing GradCAM: {str(e)}")
|
|
|
478 |
return "Error analyzing GradCAM visualization"
|
479 |
|
480 |
# Function to generate caption for original image
|