altndrr commited on
Commit
0da80f6
1 Parent(s): c8d5da7

Organise layout and interactions

Browse files
Files changed (1) hide show
  1. app.py +18 -7
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
- orig_image = gr.Image(
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.ClearButton([curr_image, orig_image])
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=[orig_image],
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
- curr_image.upload(prepare_image, [curr_image], [curr_image, orig_image])
91
- curr_image.clear(lambda: None, [], [orig_image])
92
- orig_image.change(prepare_image, [orig_image], [curr_image, orig_image])
 
 
 
 
 
 
 
 
 
 
93
  run_button.click(image_inference, [curr_image, alpha_slider], [output_label])
94
 
95
 
96
  if __name__ == "__main__":
97
  demo.queue()
98
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
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()