Spaces:
Sleeping
Sleeping
Use tab container for image components
Browse files
app.py
CHANGED
@@ -153,18 +153,12 @@ def build_gradio_app(queues, command):
|
|
153 |
css = """#anno-img .mask {opacity: 0.5; transition: all 0.2s ease-in-out;}
|
154 |
#anno-img .mask.active {opacity: 0.7}"""
|
155 |
|
156 |
-
def
|
157 |
assets_dir = os.path.join(os.path.dirname(__file__), "assets")
|
158 |
app_images = list(filter(lambda x: x.startswith("app_image"), os.listdir(assets_dir)))
|
159 |
app_images.sort()
|
160 |
return [{"image": os.path.join(assets_dir, x)} for x in app_images]
|
161 |
|
162 |
-
def on_prompt_opt(index):
|
163 |
-
click_img = gr.Image(None, visible=index == 0)
|
164 |
-
draw_img = gr.ImageEditor(None, visible=index != 0)
|
165 |
-
anno_img = gr.AnnotatedImage(None)
|
166 |
-
return click_img, draw_img, anno_img
|
167 |
-
|
168 |
def on_reset_btn():
|
169 |
click_img, draw_img = gr.Image(None), gr.ImageEditor(None)
|
170 |
anno_img = gr.AnnotatedImage(None)
|
@@ -207,25 +201,23 @@ def build_gradio_app(queues, command):
|
|
207 |
annotations = [(x, y) for x, y in zip(masks, texts)]
|
208 |
return inputs["img"][:, :, ::-1], annotations
|
209 |
|
210 |
-
app = gr.Blocks(title=title, theme=theme, css=css).__enter__()
|
211 |
-
gr.Markdown(header)
|
212 |
container, column = gr.Row().__enter__(), gr.Column().__enter__()
|
213 |
-
click_img = gr_ext.ImagePrompter(show_label=False)
|
214 |
-
|
215 |
-
interactions = "LeftClick (FG) | MiddleClick (BG) | PressMove (Box) | Draw (Sketch)"
|
216 |
gr.Markdown("<h3 style='text-align: center'>[π±οΈ | ποΈ]: ππ {} ππ </h3>".format(interactions))
|
217 |
-
row = gr.Row().__enter__()
|
218 |
-
prompt_opt = gr.Radio(["Point+Box", "Sketch"], label="Prompt", type="index", value="Point+Box")
|
219 |
point_opt = gr.Radio(["Batch", "Ensemble"], label="Multipoint", type="index", value="Batch")
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
gr.
|
|
|
224 |
_, _, column = row.__exit__(), column.__exit__(), gr.Column().__enter__()
|
225 |
anno_img = gr.AnnotatedImage(elem_id="anno-img", show_label=False)
|
226 |
reset_btn.click(on_reset_btn, [], [click_img, draw_img, anno_img])
|
227 |
submit_btn.click(on_submit_btn, [click_img, draw_img, prompt_opt, point_opt], [anno_img])
|
228 |
-
|
|
|
229 |
column.__exit__(), container.__exit__(), app.__exit__()
|
230 |
return app
|
231 |
|
|
|
153 |
css = """#anno-img .mask {opacity: 0.5; transition: all 0.2s ease-in-out;}
|
154 |
#anno-img .mask.active {opacity: 0.7}"""
|
155 |
|
156 |
+
def get_click_examples():
|
157 |
assets_dir = os.path.join(os.path.dirname(__file__), "assets")
|
158 |
app_images = list(filter(lambda x: x.startswith("app_image"), os.listdir(assets_dir)))
|
159 |
app_images.sort()
|
160 |
return [{"image": os.path.join(assets_dir, x)} for x in app_images]
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
def on_reset_btn():
|
163 |
click_img, draw_img = gr.Image(None), gr.ImageEditor(None)
|
164 |
anno_img = gr.AnnotatedImage(None)
|
|
|
201 |
annotations = [(x, y) for x, y in zip(masks, texts)]
|
202 |
return inputs["img"][:, :, ::-1], annotations
|
203 |
|
204 |
+
app, _ = gr.Blocks(title=title, theme=theme, css=css).__enter__(), gr.Markdown(header)
|
|
|
205 |
container, column = gr.Row().__enter__(), gr.Column().__enter__()
|
206 |
+
click_tab, click_img = gr.Tab("Point+Box").__enter__(), gr_ext.ImagePrompter(show_label=False)
|
207 |
+
interactions = "LeftClick (FG) | MiddleClick (BG) | PressMove (Box)"
|
|
|
208 |
gr.Markdown("<h3 style='text-align: center'>[π±οΈ | ποΈ]: ππ {} ππ </h3>".format(interactions))
|
|
|
|
|
209 |
point_opt = gr.Radio(["Batch", "Ensemble"], label="Multipoint", type="index", value="Batch")
|
210 |
+
gr.Examples(get_click_examples(), inputs=[click_img])
|
211 |
+
_, draw_tab = click_tab.__exit__(), gr.Tab("Sketch").__enter__()
|
212 |
+
draw_img, _ = gr.ImageEditor(show_label=False), draw_tab.__exit__()
|
213 |
+
prompt_opt = gr.Radio(["Click", "Draw"], type="index", visible=False, value="Click")
|
214 |
+
row, reset_btn, submit_btn = gr.Row().__enter__(), gr.Button("Reset"), gr.Button("Execute")
|
215 |
_, _, column = row.__exit__(), column.__exit__(), gr.Column().__enter__()
|
216 |
anno_img = gr.AnnotatedImage(elem_id="anno-img", show_label=False)
|
217 |
reset_btn.click(on_reset_btn, [], [click_img, draw_img, anno_img])
|
218 |
submit_btn.click(on_submit_btn, [click_img, draw_img, prompt_opt, point_opt], [anno_img])
|
219 |
+
click_tab.select(lambda: "Click", [], [prompt_opt])
|
220 |
+
draw_tab.select(lambda: "Draw", [], [prompt_opt])
|
221 |
column.__exit__(), container.__exit__(), app.__exit__()
|
222 |
return app
|
223 |
|