Jyothirmai commited on
Commit
2422226
1 Parent(s): a98b86e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -52,17 +52,19 @@ def getCaption(imgID):
52
  real_captions = {"1" : "No acute cardiopulmonary abnormality. 2. Stable bilateral emphysematous and lower lobe fibrotic changes. Bilateral emphysematous again noted and lower lobe fibrotic changes. Postsurgical changes of the chest including CABG procedure, stable. Stable valve artifact. There are no focal areas of consolidation. No large pleural effusions. No evidence of pneumothorax. Degenerative changes noted of the visualized thoracic spine. Nodular right lower lobe opacity, XXXX nipple XXXX. Contour abnormality of the posterior aspect of the right 7th rib again noted, stable.",
53
  "2":"Hypoinflation with bibasilar focal atelectasis. Lung volumes are XXXX. XXXX opacities are present in both lung bases. A hiatal hernia is present. Heart and pulmonary XXXX are normal.",
54
  "3":"No acute cardiopulmonary process. 2. 9 mm left lower lobe pulmonary nodule not definitively calcified. Recommend comparison with prior images to document stability. If none are available consider nonemergent XXXX chest for further characterization. . Normal heart size and mediastinal contours. The lungs are free of any focal airspace disease. In the left lung base, there is a 9 mm nodule that not definitively calcified. No pneumothorax or pleural effusion. No acute bony abnormalities.",
55
- "4":"No acute disease. Left lung nodule. Correlate with prior films if available. If none are available, followup imaging in 6 months is suggested. The heart is normal in size. The mediastinum is unremarkable. Small nodule seen in the left upper lung, possibly granuloma. The lungs are otherwise clear."}
 
 
56
 
57
- print(real_captions[imgID])
58
  return real_captions[imgID]
59
 
60
  def getImageID(imgID):
 
 
61
  imgIDs = {"1":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR412_IM-2056_0",
62
  "2":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR545_IM-2149_0",
63
  "3":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR849_IM-2371_0",
64
  "4":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR2163_IM-0779_0"}
65
- print(imgIDs[imgID])
66
  return imgIDs[imgID]
67
 
68
  def predict(img, model_name, max_tokens, temperature, imgID):
@@ -73,9 +75,11 @@ def predict(img, model_name, max_tokens, temperature, imgID):
73
  elif model_name == "ViT-CoAttention":
74
  return generate_caption_vitCoAtt(img), getCaption(imgID)
75
  elif model_name == "Baseline Model CNN-RNN":
76
- print(imgID)
77
  img = getImageID(imgID)
78
- return generate_caption_cnnrnn(img), getCaption(imgID)
 
 
 
79
  else:
80
  return "select a model","select an image"
81
 
 
52
  real_captions = {"1" : "No acute cardiopulmonary abnormality. 2. Stable bilateral emphysematous and lower lobe fibrotic changes. Bilateral emphysematous again noted and lower lobe fibrotic changes. Postsurgical changes of the chest including CABG procedure, stable. Stable valve artifact. There are no focal areas of consolidation. No large pleural effusions. No evidence of pneumothorax. Degenerative changes noted of the visualized thoracic spine. Nodular right lower lobe opacity, XXXX nipple XXXX. Contour abnormality of the posterior aspect of the right 7th rib again noted, stable.",
53
  "2":"Hypoinflation with bibasilar focal atelectasis. Lung volumes are XXXX. XXXX opacities are present in both lung bases. A hiatal hernia is present. Heart and pulmonary XXXX are normal.",
54
  "3":"No acute cardiopulmonary process. 2. 9 mm left lower lobe pulmonary nodule not definitively calcified. Recommend comparison with prior images to document stability. If none are available consider nonemergent XXXX chest for further characterization. . Normal heart size and mediastinal contours. The lungs are free of any focal airspace disease. In the left lung base, there is a 9 mm nodule that not definitively calcified. No pneumothorax or pleural effusion. No acute bony abnormalities.",
55
+ "4":"No acute disease. Left lung nodule. Correlate with prior films if available. If none are available, followup imaging in 6 months is suggested. The heart is normal in size. The mediastinum is unremarkable. Small nodule seen in the left upper lung, possibly granuloma. The lungs are otherwise clear.",
56
+ "5": "No Actual Caption",
57
+ "6": "No Actual Caption"}
58
 
 
59
  return real_captions[imgID]
60
 
61
  def getImageID(imgID):
62
+ if imgID == "5" or imgID == "6":
63
+ return 0
64
  imgIDs = {"1":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR412_IM-2056_0",
65
  "2":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR545_IM-2149_0",
66
  "3":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR849_IM-2371_0",
67
  "4":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR2163_IM-0779_0"}
 
68
  return imgIDs[imgID]
69
 
70
  def predict(img, model_name, max_tokens, temperature, imgID):
 
75
  elif model_name == "ViT-CoAttention":
76
  return generate_caption_vitCoAtt(img), getCaption(imgID)
77
  elif model_name == "Baseline Model CNN-RNN":
 
78
  img = getImageID(imgID)
79
+ if img != 0:
80
+ return generate_caption_cnnrnn(img), getCaption(imgID)
81
+ else:
82
+ return "The images 5 and 6 are not chest xrays and the baseline model cannot be implemented try a different sample", "The images 5 and 6 are not chest xrays and the baseline model cannot be implemented try a different sample"
83
  else:
84
  return "select a model","select an image"
85