piyushgrover commited on
Commit
8200379
·
1 Parent(s): 3ca08e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -100,26 +100,26 @@ with gr.Blocks() as app:
100
  </p>
101
  """
102
  )
103
- with gr.Row(visible=True) as top_pred_cls_col:
104
  with gr.Column():
105
  example_images = gr.Gallery(allow_preview=False, label='Select image ', info='',
106
  value=[img[0] for img in sample_images], columns=6, rows=2)
107
 
108
  with gr.Column():
109
  with gr.Row():
110
- top_pred_image = gr.Image(label='Upload Image or Select from the gallery')
111
 
112
  with gr.Row():
113
  if_show_grad_cam = gr.Checkbox(value=True, label='Show Class Activation Map (What the model sees)?')
114
 
115
  with gr.Row():
116
- top_class_btn = gr.Button("Submit", variant='primary')
117
- tc_clear_btn = gr.ClearButton()
118
 
119
- with gr.Row(visible=True) as top_class_output:
120
- with gr.Column(visible=True) as top_class_output:
121
- top_class_output_img = gr.Image(interactive=False, label='Prediction Output')
122
- with gr.Column(visible=True) as top_class_output:
123
  grad_cam_out = gr.Image(interactive=False, visible=True, label='CAM Outcome')
124
 
125
 
@@ -138,21 +138,22 @@ with gr.Blocks() as app:
138
 
139
  def clear_data():
140
  return {
141
- top_pred_image: None,
142
- top_class_output_img: None
 
143
  }
144
 
145
 
146
- tc_clear_btn.click(clear_data, None, [top_pred_image, top_class_output_img])
147
 
148
 
149
  def on_select(evt: gr.SelectData):
150
  return {
151
- top_pred_image: sample_images[evt.index][0]
152
  }
153
 
154
 
155
- example_images.select(on_select, None, top_pred_image)
156
 
157
 
158
  def plot_image(image, boxes):
@@ -232,20 +233,20 @@ with gr.Blocks() as app:
232
  return [plotted_img, cam_image]
233
 
234
 
235
- def top_class_img_upload(input_img, if_cam):
236
  if input_img is not None:
237
  imgs = predict(input_img, show_cam=if_cam)
238
 
239
  return {
240
- top_class_output_img: imgs[0],
241
  grad_cam_out: imgs[1]
242
  }
243
 
244
 
245
- top_class_btn.click(
246
- top_class_img_upload,
247
- [top_pred_image, if_show_grad_cam],
248
- [top_class_output_img, grad_cam_out]
249
  )
250
 
251
  '''
 
100
  </p>
101
  """
102
  )
103
+ with gr.Row(visible=True) as pred_cls_col:
104
  with gr.Column():
105
  example_images = gr.Gallery(allow_preview=False, label='Select image ', info='',
106
  value=[img[0] for img in sample_images], columns=6, rows=2)
107
 
108
  with gr.Column():
109
  with gr.Row():
110
+ pred_image = gr.Image(label='Upload Image or Select from the gallery')
111
 
112
  with gr.Row():
113
  if_show_grad_cam = gr.Checkbox(value=True, label='Show Class Activation Map (What the model sees)?')
114
 
115
  with gr.Row():
116
+ submit_btn = gr.Button("Submit", variant='primary')
117
+ clear_btn = gr.ClearButton()
118
 
119
+ with gr.Row(visible=True) as output_bk:
120
+ with gr.Column(visible=True) as output_bk:
121
+ output_img = gr.Image(interactive=False, label='Prediction Output')
122
+ with gr.Column(visible=True) as output_bk:
123
  grad_cam_out = gr.Image(interactive=False, visible=True, label='CAM Outcome')
124
 
125
 
 
138
 
139
  def clear_data():
140
  return {
141
+ pred_image: None,
142
+ output_img: None,
143
+ grad_cam_out: None
144
  }
145
 
146
 
147
+ clear_btn.click(clear_data, None, [pred_image, output_img])
148
 
149
 
150
  def on_select(evt: gr.SelectData):
151
  return {
152
+ pred_image: sample_images[evt.index][0]
153
  }
154
 
155
 
156
+ example_images.select(on_select, None, pred_image)
157
 
158
 
159
  def plot_image(image, boxes):
 
233
  return [plotted_img, cam_image]
234
 
235
 
236
+ def img_upload(input_img, if_cam):
237
  if input_img is not None:
238
  imgs = predict(input_img, show_cam=if_cam)
239
 
240
  return {
241
+ output_img: imgs[0],
242
  grad_cam_out: imgs[1]
243
  }
244
 
245
 
246
+ submit_btn.click(
247
+ img_upload,
248
+ [pred_image, if_show_grad_cam],
249
+ [output_img, grad_cam_out]
250
  )
251
 
252
  '''