Jyothirmai commited on
Commit
ea41590
1 Parent(s): 0a2f651

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -22
app.py CHANGED
@@ -38,46 +38,47 @@ with gr.Row():
38
  with gr.Row():
39
  with gr.Column(): # Column for dropdowns and model choice
40
  max_tokens = gr.Dropdown(list(range(50, 101)), label="Max Tokens", value=75)
41
- temperature = gr.Slider(0.5, 0.9, step=0.1, label="Temperature", value=0.7)
 
42
 
43
  model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention", "Baseline Model CNN-RNN"], label="Select Model")
44
  generate_button = gr.Button("Generate Caption")
45
 
46
 
47
- real_captions = {"0" : "No acute cardiopulmonary abnormality. Low lung volumes. Heart size and mediastinal contour within normal limits. No focal air space consolidation, pneumothorax, or pleural effusion. Mild thoracic spine degenerative change.",
48
- "1":"Left basilar atelectasis and/or infiltrate, with no radiographic evidence of tuberculosis. Heart size upper limits of normal. Small amount of left basilar airspace disease. The right lung is clear. There are no cavitary lesions seen. No pneumothorax. No pleural effusions",
49
- "2":"Cardiomegaly and small bilateral pleural effusions. Abnormal pulmonary opacities most suggestive of pulmonary edema, primary differential diagnosis includes infection and aspiration, clinical correlation recommended Moderate-to-marked enlargement of the cardiac silhouette, mediastinal contours appear similar to prior. Mild bilateral posterior sulcus blunting, interstitial and alveolar opacities greatest in the central lungs and bases with indistinct vascular margination.",
50
- "3":"Severe cardiomegaly. Limited mediastinal evaluation given body habitus and lordotic projection. Recommend XXXX for further evaluation of mediastinum given T/Spine injury noted on C/Spine imaging. Critical result notification documented through Primordial. Lordotic projection and large body habitus. Limited mediastinal evaluation. Severe cardiomegaly. No visualized pneumothorax. No large effusion or airspace disease. No fracture."}
51
 
52
- imgIDs = {"0":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR192_IM-0598_0",
53
- "1":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR194_IM-0609_0",
54
- "2":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR2637_IM-1122_0",
55
- "3":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR1111_IM-0077_0"}
56
 
57
 
58
  caption = gr.Textbox(label="Generated Caption")
59
  real_caption = gr.Textbox(label="Actual Caption")
60
 
61
- def predict(img, model_name, max_tokens, temperature, examples):
62
  if model_name == "CLIP-GPT2":
63
- return generate_caption_clipgpt(img, max_tokens, temperature), getCaption(examples)
64
  elif model_name == "ViT-GPT2":
65
- return generate_caption_vitgpt(img, max_tokens, temperature), getCaption(examples)
66
  elif model_name == "ViT-CoAttention":
67
- return generate_caption_vitCoAtt(img), getCaption(examples)
68
  elif model_name == "Baseline Model CNN-RNN":
69
- img = getImageID(examples)
70
- return generate_caption_cnnrnn(img), getCaption(examples)
71
  else:
72
  return "Caption generation for this model is not yet implemented."
73
 
74
- def getCaption(examples):
75
- print(real_captions[examples[1]])
76
- return real_captions[examples[1]]
77
 
78
- def getImageID(examples):
79
- print(imgIDs[examples[1]])
80
- return imgIDs[examples[1]]
81
 
82
  examples = [[f"example{i}.jpg"] for i in range(1,7)]
83
 
@@ -86,7 +87,7 @@ title = "MedViT: A Vision Transformer-Driven Method for Generating Medical Repor
86
 
87
  interface = gr.Interface(
88
  fn=predict,
89
- inputs = [image, model_choice, max_tokens, temperature, examples],
90
  theme="sudeepshouche/minimalist",
91
  outputs=[caption,real_caption],
92
  examples = examples,
 
38
  with gr.Row():
39
  with gr.Column(): # Column for dropdowns and model choice
40
  max_tokens = gr.Dropdown(list(range(50, 101)), label="Max Tokens", value=75)
41
+ temperature = gr.Slider(0.5, 0.9, step=0.1, label="Temperature", value=0.9)
42
+ imgID = gr.Dropdown(list(range(1,6)), label="Example Image Selected", value=1)
43
 
44
  model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention", "Baseline Model CNN-RNN"], label="Select Model")
45
  generate_button = gr.Button("Generate Caption")
46
 
47
 
48
+ real_captions = {"1" : "No acute cardiopulmonary abnormality. Low lung volumes. Heart size and mediastinal contour within normal limits. No focal air space consolidation, pneumothorax, or pleural effusion. Mild thoracic spine degenerative change.",
49
+ "2":"Left basilar atelectasis and/or infiltrate, with no radiographic evidence of tuberculosis. Heart size upper limits of normal. Small amount of left basilar airspace disease. The right lung is clear. There are no cavitary lesions seen. No pneumothorax. No pleural effusions",
50
+ "3":"Cardiomegaly and small bilateral pleural effusions. Abnormal pulmonary opacities most suggestive of pulmonary edema, primary differential diagnosis includes infection and aspiration, clinical correlation recommended Moderate-to-marked enlargement of the cardiac silhouette, mediastinal contours appear similar to prior. Mild bilateral posterior sulcus blunting, interstitial and alveolar opacities greatest in the central lungs and bases with indistinct vascular margination.",
51
+ "4":"Severe cardiomegaly. Limited mediastinal evaluation given body habitus and lordotic projection. Recommend XXXX for further evaluation of mediastinum given T/Spine injury noted on C/Spine imaging. Critical result notification documented through Primordial. Lordotic projection and large body habitus. Limited mediastinal evaluation. Severe cardiomegaly. No visualized pneumothorax. No large effusion or airspace disease. No fracture."}
52
 
53
+ imgIDs = {"1":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR192_IM-0598_0",
54
+ "2":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR194_IM-0609_0",
55
+ "3":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR2637_IM-1122_0",
56
+ "4":"/content/drive/MyDrive/cnn-rnn/NLMCXR_png/CXR1111_IM-0077_0"}
57
 
58
 
59
  caption = gr.Textbox(label="Generated Caption")
60
  real_caption = gr.Textbox(label="Actual Caption")
61
 
62
+ def predict(img, model_name, max_tokens, temperature, imgID):
63
  if model_name == "CLIP-GPT2":
64
+ return generate_caption_clipgpt(img, max_tokens, temperature), getCaption(imgID)
65
  elif model_name == "ViT-GPT2":
66
+ return generate_caption_vitgpt(img, max_tokens, temperature), getCaption(imgID)
67
  elif model_name == "ViT-CoAttention":
68
+ return generate_caption_vitCoAtt(img), getCaption(imgID)
69
  elif model_name == "Baseline Model CNN-RNN":
70
+ img = getImageID(imgID)
71
+ return generate_caption_cnnrnn(img), getCaption(imgID)
72
  else:
73
  return "Caption generation for this model is not yet implemented."
74
 
75
+ def getCaption(imgID):
76
+ print(real_captions[imgID])
77
+ return real_captions[imgID]
78
 
79
+ def getImageID(imgID):
80
+ print(imgIDs[imgID])
81
+ return imgIDs[imgID]
82
 
83
  examples = [[f"example{i}.jpg"] for i in range(1,7)]
84
 
 
87
 
88
  interface = gr.Interface(
89
  fn=predict,
90
+ inputs = [image, model_choice, max_tokens, temperature, imgID],
91
  theme="sudeepshouche/minimalist",
92
  outputs=[caption,real_caption],
93
  examples = examples,