rtik007 commited on
Commit
a4ec3c0
·
verified ·
1 Parent(s): 032491b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -29,13 +29,30 @@ transform = transforms.Compose([
29
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
30
  ])
31
 
32
- # Class names for the 14 diseases (labels from ChestX-ray14 dataset)
33
  class_names = [
34
  'Atelectasis', 'Cardiomegaly', 'Effusion', 'Infiltration', 'Mass',
35
  'Nodule', 'Pneumonia', 'Pneumothorax', 'Consolidation', 'Edema',
36
  'Emphysema', 'Fibrosis', 'Pleural Thickening', 'Hernia'
37
  ]
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Prediction function
40
  def predict_disease(image):
41
  image = transform(image).unsqueeze(0).to(device) # Transform and add batch dimension
@@ -43,7 +60,12 @@ def predict_disease(image):
43
  with torch.no_grad():
44
  outputs = model(image)
45
  outputs = outputs.cpu().numpy().flatten()
46
- result = {class_name: float(prob) for class_name, prob in zip(class_names, outputs)}
 
 
 
 
 
47
  return result
48
 
49
  # Gradio Interface
 
29
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
30
  ])
31
 
32
+ # Class names and their interpretations for the 14 diseases
33
  class_names = [
34
  'Atelectasis', 'Cardiomegaly', 'Effusion', 'Infiltration', 'Mass',
35
  'Nodule', 'Pneumonia', 'Pneumothorax', 'Consolidation', 'Edema',
36
  'Emphysema', 'Fibrosis', 'Pleural Thickening', 'Hernia'
37
  ]
38
 
39
+ interpretations = {
40
+ 'Atelectasis': "Partial or complete collapse of the lung.",
41
+ 'Cardiomegaly': "Enlargement of the heart.",
42
+ 'Effusion': "Fluid accumulation in the chest cavity.",
43
+ 'Infiltration': "Substances such as fluid in the lungs.",
44
+ 'Mass': "An abnormal growth in the lung.",
45
+ 'Nodule': "Small round or oval-shaped growth in the lung.",
46
+ 'Pneumonia': "Infection causing inflammation in the air sacs.",
47
+ 'Pneumothorax': "Air in the pleural space causing lung collapse.",
48
+ 'Consolidation': "Lung tissue that has filled with liquid.",
49
+ 'Edema': "Excess fluid in the lungs.",
50
+ 'Emphysema': "Damage to air sacs causing difficulty breathing.",
51
+ 'Fibrosis': "Thickening or scarring of lung tissue.",
52
+ 'Pleural Thickening': "Thickening of the pleura (lining of the lungs).",
53
+ 'Hernia': "Displacement of an organ through a structure."
54
+ }
55
+
56
  # Prediction function
57
  def predict_disease(image):
58
  image = transform(image).unsqueeze(0).to(device) # Transform and add batch dimension
 
60
  with torch.no_grad():
61
  outputs = model(image)
62
  outputs = outputs.cpu().numpy().flatten()
63
+
64
+ # Result with interpretations
65
+ result = {
66
+ f"{class_name} ({interpretations[class_name]})": float(prob)
67
+ for class_name, prob in zip(class_names, outputs)
68
+ }
69
  return result
70
 
71
  # Gradio Interface