Update app.py
Browse files
app.py
CHANGED
|
@@ -442,18 +442,33 @@ 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 |
-
if len(parts) > 1: # Make sure we have activation levels to split
|
| 448 |
-
formatted_text = parts[0].replace("high", "**High activation**:\n") + "\n\n"
|
| 449 |
-
formatted_text += "**Moderate activation**:\n" + parts[1].split("moderate")[1] + "\n\n"
|
| 450 |
-
formatted_text += "**Low activation**:\n" + parts[2].split("low")[1]
|
| 451 |
-
return formatted_text.strip()
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
return caption
|
| 454 |
|
| 455 |
except Exception as e:
|
| 456 |
st.error(f"Error analyzing GradCAM: {str(e)}")
|
|
|
|
| 457 |
return "Error analyzing GradCAM visualization"
|
| 458 |
|
| 459 |
# Function to generate caption for original image
|
|
|
|
| 442 |
# Decode the output
|
| 443 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
| 444 |
|
| 445 |
+
# Print debug info
|
| 446 |
+
st.write("Debug - Raw caption:", caption)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
|
| 448 |
+
# Split and format the text differently
|
| 449 |
+
if "high activation" in caption.lower():
|
| 450 |
+
# Extract the parts for each activation level
|
| 451 |
+
high_part = caption[caption.lower().find("high activation"):].split("moderate")[0].strip()
|
| 452 |
+
moderate_part = "moderate" + caption.split("moderate")[1].split("low")[0].strip()
|
| 453 |
+
low_part = "low" + caption.split("low")[1].strip()
|
| 454 |
+
|
| 455 |
+
formatted_text = f"""**High activation**:
|
| 456 |
+
{high_part.replace('high activation :', '').strip()}
|
| 457 |
+
|
| 458 |
+
**Moderate activation**:
|
| 459 |
+
{moderate_part.replace('moderate activation :', '').strip()}
|
| 460 |
+
|
| 461 |
+
**Low activation**:
|
| 462 |
+
{low_part.replace('low activation :', '').strip()}"""
|
| 463 |
+
|
| 464 |
+
return formatted_text
|
| 465 |
+
|
| 466 |
+
# If we can't parse it properly, return the original caption
|
| 467 |
return caption
|
| 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
|