Spaces:
Runtime error
Runtime error
moved gradcam inside app
Browse files
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
-
from PIL import Image
|
| 4 |
-
|
| 5 |
from app.predictor import predict_disease, compute_ai_risk
|
| 6 |
from app.gradcam import generate_gradcam
|
| 7 |
|
|
@@ -13,10 +11,9 @@ def predict(image):
|
|
| 13 |
# 2️⃣ GradCAM heatmap
|
| 14 |
heatmap = generate_gradcam(tensor, original)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
if heatmap.max() <= 1:
|
| 18 |
heatmap = heatmap * 255
|
| 19 |
-
|
| 20 |
heatmap = heatmap.astype(np.uint8)
|
| 21 |
|
| 22 |
# 3️⃣ Risk prediction
|
|
@@ -30,19 +27,27 @@ Confidence: {round(confidence*100,2)} %
|
|
| 30 |
Risk Level: {risk}
|
| 31 |
"""
|
| 32 |
|
| 33 |
-
# 🔴 RETURN TEXT FIRST, IMAGE SECOND
|
| 34 |
return report, heatmap
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
|
|
|
|
|
|
| 3 |
from app.predictor import predict_disease, compute_ai_risk
|
| 4 |
from app.gradcam import generate_gradcam
|
| 5 |
|
|
|
|
| 11 |
# 2️⃣ GradCAM heatmap
|
| 12 |
heatmap = generate_gradcam(tensor, original)
|
| 13 |
|
| 14 |
+
# Convert to displayable image
|
| 15 |
if heatmap.max() <= 1:
|
| 16 |
heatmap = heatmap * 255
|
|
|
|
| 17 |
heatmap = heatmap.astype(np.uint8)
|
| 18 |
|
| 19 |
# 3️⃣ Risk prediction
|
|
|
|
| 27 |
Risk Level: {risk}
|
| 28 |
"""
|
| 29 |
|
|
|
|
| 30 |
return report, heatmap
|
| 31 |
|
| 32 |
|
| 33 |
+
# 🔴 BLOCKS UI (no more Interface)
|
| 34 |
+
with gr.Blocks(title="CardioGuard AI") as demo:
|
| 35 |
+
|
| 36 |
+
gr.Markdown("# 🫀 CardioGuard AI")
|
| 37 |
+
gr.Markdown("Upload Chest X-ray to detect heart disease")
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
image_input = gr.Image(type="pil", label="Upload X-ray")
|
| 41 |
+
|
| 42 |
+
run_btn = gr.Button("Analyze")
|
| 43 |
+
|
| 44 |
+
report_output = gr.Textbox(label="AI Diagnosis Report")
|
| 45 |
+
heatmap_output = gr.Image(label="GradCAM Heatmap")
|
| 46 |
+
|
| 47 |
+
run_btn.click(
|
| 48 |
+
fn=predict,
|
| 49 |
+
inputs=image_input,
|
| 50 |
+
outputs=[report_output, heatmap_output]
|
| 51 |
+
)
|
| 52 |
|
| 53 |
demo.launch()
|