Spaces:
Sleeping
Sleeping
Commit
·
8200379
1
Parent(s):
3ca08e2
Update app.py
Browse files
app.py
CHANGED
@@ -100,26 +100,26 @@ with gr.Blocks() as app:
|
|
100 |
</p>
|
101 |
"""
|
102 |
)
|
103 |
-
with gr.Row(visible=True) as
|
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 |
-
|
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 |
-
|
117 |
-
|
118 |
|
119 |
-
with gr.Row(visible=True) as
|
120 |
-
with gr.Column(visible=True) as
|
121 |
-
|
122 |
-
with gr.Column(visible=True) as
|
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 |
-
|
142 |
-
|
|
|
143 |
}
|
144 |
|
145 |
|
146 |
-
|
147 |
|
148 |
|
149 |
def on_select(evt: gr.SelectData):
|
150 |
return {
|
151 |
-
|
152 |
}
|
153 |
|
154 |
|
155 |
-
example_images.select(on_select, None,
|
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
|
236 |
if input_img is not None:
|
237 |
imgs = predict(input_img, show_cam=if_cam)
|
238 |
|
239 |
return {
|
240 |
-
|
241 |
grad_cam_out: imgs[1]
|
242 |
}
|
243 |
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
[
|
248 |
-
[
|
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 |
'''
|