rtik007 commited on
Commit
e873a09
·
verified ·
1 Parent(s): d8a6e20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -11,6 +11,24 @@ model = ViTForImageClassification.from_pretrained(model_name)
11
  image_processor = ViTImageProcessor.from_pretrained(model_name)
12
  model.eval()
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Function to apply Grad-CAM visualization
15
  def generate_grad_cam(image, target_layer):
16
  # Preprocess the image
@@ -53,8 +71,7 @@ def predict_and_explain(image):
53
  logits = outputs.logits
54
  predicted_class_idx = logits.argmax(-1).item()
55
 
56
- # Predefined medical conditions (adjust based on your dataset)
57
- labels = ["Class 1 - Normal", "Class 2 - Condition A", "Class 3 - Condition B"]
58
  predicted_label = labels[predicted_class_idx]
59
 
60
  # Generate Grad-CAM heatmap
@@ -82,8 +99,8 @@ interface = gr.Interface(
82
  "text",
83
  gr.Image(type="file", label="Grad-CAM Visualization")
84
  ],
85
- title="Medical Image Analysis Tool with Explainability",
86
- description="Upload an X-ray or MRI image to get a prediction for a medical condition with explainability through Grad-CAM.",
87
  live=True
88
  )
89
 
 
11
  image_processor = ViTImageProcessor.from_pretrained(model_name)
12
  model.eval()
13
 
14
+ # NIH Chest X-ray predefined conditions
15
+ labels = [
16
+ "Atelectasis",
17
+ "Cardiomegaly",
18
+ "Effusion",
19
+ "Infiltration",
20
+ "Mass",
21
+ "Nodule",
22
+ "Pneumonia",
23
+ "Pneumothorax",
24
+ "Consolidation",
25
+ "Edema",
26
+ "Emphysema",
27
+ "Fibrosis",
28
+ "Pleural Thickening",
29
+ "Hernia"
30
+ ]
31
+
32
  # Function to apply Grad-CAM visualization
33
  def generate_grad_cam(image, target_layer):
34
  # Preprocess the image
 
71
  logits = outputs.logits
72
  predicted_class_idx = logits.argmax(-1).item()
73
 
74
+ # Get the predicted label based on NIH Chest X-ray conditions
 
75
  predicted_label = labels[predicted_class_idx]
76
 
77
  # Generate Grad-CAM heatmap
 
99
  "text",
100
  gr.Image(type="file", label="Grad-CAM Visualization")
101
  ],
102
+ title="Medical Image Analysis Tool with NIH Chest X-ray",
103
+ description="Upload a Chest X-ray image to get a prediction for common thoracic conditions based on the NIH dataset, with explainability through Grad-CAM.",
104
  live=True
105
  )
106