Spaces:
Running
Running
Organise layout and interactions
Browse files
app.py
CHANGED
@@ -65,34 +65,45 @@ def image_inference(image: gr.Image, alpha: Optional[float] = None):
|
|
65 |
|
66 |
|
67 |
with gr.Blocks(analytics_enabled=True, title=PAPER_TITLE, theme="soft") as demo:
|
|
|
68 |
gr.Markdown(MARKDOWN_DESCRIPTION)
|
69 |
with gr.Row():
|
70 |
with gr.Column():
|
71 |
curr_image = gr.Image(label="input", type="pil")
|
72 |
-
|
73 |
label="orig. image", type="pil", visible=False, interactive=False
|
74 |
)
|
75 |
alpha_slider = gr.Slider(0.0, 1.0, value=0.7, step=0.1, label="alpha")
|
76 |
with gr.Row():
|
77 |
-
clear_button = gr.
|
78 |
run_button = gr.Button(value="Submit", variant="primary")
|
79 |
with gr.Column():
|
80 |
output_label = gr.Label(label="output", num_top_classes=5)
|
81 |
examples = gr.Examples(
|
82 |
examples=glob(os.path.join(os.path.dirname(__file__), "examples", "*.jpg")),
|
83 |
-
inputs=[
|
84 |
outputs=[output_label],
|
85 |
fn=image_inference,
|
86 |
cache_examples=True,
|
87 |
)
|
88 |
gr.Markdown(f"Check out the <a href={PAPER_URL}>original paper</a> for more information.")
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
run_button.click(image_inference, [curr_image, alpha_slider], [output_label])
|
94 |
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
demo.queue()
|
98 |
-
demo.launch(
|
|
|
65 |
|
66 |
|
67 |
with gr.Blocks(analytics_enabled=True, title=PAPER_TITLE, theme="soft") as demo:
|
68 |
+
# LAYOUT
|
69 |
gr.Markdown(MARKDOWN_DESCRIPTION)
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
curr_image = gr.Image(label="input", type="pil")
|
73 |
+
_orig_image = gr.Image(
|
74 |
label="orig. image", type="pil", visible=False, interactive=False
|
75 |
)
|
76 |
alpha_slider = gr.Slider(0.0, 1.0, value=0.7, step=0.1, label="alpha")
|
77 |
with gr.Row():
|
78 |
+
clear_button = gr.Button(value="Clear", variant="secondary")
|
79 |
run_button = gr.Button(value="Submit", variant="primary")
|
80 |
with gr.Column():
|
81 |
output_label = gr.Label(label="output", num_top_classes=5)
|
82 |
examples = gr.Examples(
|
83 |
examples=glob(os.path.join(os.path.dirname(__file__), "examples", "*.jpg")),
|
84 |
+
inputs=[_orig_image],
|
85 |
outputs=[output_label],
|
86 |
fn=image_inference,
|
87 |
cache_examples=True,
|
88 |
)
|
89 |
gr.Markdown(f"Check out the <a href={PAPER_URL}>original paper</a> for more information.")
|
90 |
|
91 |
+
# INTERACTIONS
|
92 |
+
# - change
|
93 |
+
_orig_image.change(prepare_image, [_orig_image], [curr_image, _orig_image])
|
94 |
+
|
95 |
+
# - upload
|
96 |
+
curr_image.upload(prepare_image, [curr_image], [curr_image, _orig_image])
|
97 |
+
curr_image.upload(lambda: None, [], [output_label])
|
98 |
+
|
99 |
+
# - clear
|
100 |
+
curr_image.clear(lambda: (None, None), [], [_orig_image, output_label])
|
101 |
+
|
102 |
+
# - click
|
103 |
+
clear_button.click(lambda: (None, None, None), [], [curr_image, _orig_image, output_label])
|
104 |
run_button.click(image_inference, [curr_image, alpha_slider], [output_label])
|
105 |
|
106 |
|
107 |
if __name__ == "__main__":
|
108 |
demo.queue()
|
109 |
+
demo.launch()
|