talha420 commited on
Commit
c4ffce5
·
1 Parent(s): aef342c

moved gradcam inside app

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -1,6 +1,3 @@
1
- import os
2
- os.system("pip install gradio==4.44.1 --no-cache-dir")
3
-
4
  import gradio as gr
5
  import numpy as np
6
  from app.predictor import predict_disease, compute_ai_risk
@@ -14,9 +11,13 @@ def predict(image):
14
  # 2️⃣ GradCAM heatmap
15
  heatmap = generate_gradcam(tensor, original)
16
 
17
- # Convert to displayable image
 
 
 
18
  if heatmap.max() <= 1:
19
  heatmap = heatmap * 255
 
20
  heatmap = heatmap.astype(np.uint8)
21
 
22
  # 3️⃣ Risk prediction
@@ -26,14 +27,14 @@ def predict(image):
26
  🫀 AI Clinical Report
27
 
28
  Disease: {label}
29
- Confidence: {round(confidence*100,2)} %
30
  Risk Level: {risk}
31
  """
32
 
33
  return report, heatmap
34
 
35
 
36
- # 🔴 BLOCKS UI (no more Interface)
37
  with gr.Blocks(title="CardioGuard AI") as demo:
38
 
39
  gr.Markdown("# 🫀 CardioGuard AI")
@@ -53,4 +54,10 @@ with gr.Blocks(title="CardioGuard AI") as demo:
53
  outputs=[report_output, heatmap_output]
54
  )
55
 
56
- demo.launch()
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import numpy as np
3
  from app.predictor import predict_disease, compute_ai_risk
 
11
  # 2️⃣ GradCAM heatmap
12
  heatmap = generate_gradcam(tensor, original)
13
 
14
+ # Safety check (VERY IMPORTANT for Gradio image output)
15
+ heatmap = np.array(heatmap)
16
+
17
+ # Normalize if needed
18
  if heatmap.max() <= 1:
19
  heatmap = heatmap * 255
20
+
21
  heatmap = heatmap.astype(np.uint8)
22
 
23
  # 3️⃣ Risk prediction
 
27
  🫀 AI Clinical Report
28
 
29
  Disease: {label}
30
+ Confidence: {round(confidence * 100, 2)} %
31
  Risk Level: {risk}
32
  """
33
 
34
  return report, heatmap
35
 
36
 
37
+ # 🔴 UI
38
  with gr.Blocks(title="CardioGuard AI") as demo:
39
 
40
  gr.Markdown("# 🫀 CardioGuard AI")
 
54
  outputs=[report_output, heatmap_output]
55
  )
56
 
57
+
58
+ # ✅ IMPORTANT FIX FOR SPACES / CLOUD
59
+ demo.launch(
60
+ server_name="0.0.0.0",
61
+ server_port=7860,
62
+ share=False
63
+ )