aapot commited on
Commit
9016246
·
1 Parent(s): 0799c33

More efficient input change handling

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -67,11 +67,12 @@ with gr.Blocks(title=demo_title) as demo:
67
  clear_btn = gr.Button('Clear', variant='secondary')
68
  run_btn = gr.Button('Run', variant='primary')
69
  with gr.Column():
70
- outputs = [gr.Label(label='Model prediction')]
 
71
  with gr.Accordion('See video details', open=False):
72
  with gr.Row():
73
  with gr.Column():
74
- video_embedded = gr.HTML(
75
  value=placeholder_youtube_embedded_html)
76
  with gr.Column():
77
  video_embedded2 = gr.HTML(
@@ -83,17 +84,21 @@ with gr.Blocks(title=demo_title) as demo:
83
  examples_rr = gr.Examples(examples=example_videos_rr, inputs=inputs,
84
  label='Example bad becommendations from the RegretsReporter report')
85
 
 
 
 
 
 
 
 
 
86
  run_btn.click(fn=get_video_similarity, inputs=inputs, outputs=outputs)
87
  clear_btn.click(lambda value_1, value_2, value_3: (
88
  None, None, None), inputs=inputs + outputs, outputs=inputs + outputs)
89
 
90
- input_text1.change(lambda input: update_youtube_embedded_html(
91
- input, 1) if input else placeholder_youtube_embedded_html, inputs=input_text1, outputs=video_embedded)
92
- input_text2.change(lambda input: update_youtube_embedded_html(
93
- input, 2) if input else placeholder_youtube_embedded_html, inputs=input_text2, outputs=video_embedded2)
94
- input_text1.change(lambda input: (
95
- None), inputs=input_text1, outputs=outputs)
96
- input_text2.change(lambda input: (
97
- None), inputs=input_text2, outputs=outputs)
98
 
99
  demo.launch()
 
67
  clear_btn = gr.Button('Clear', variant='secondary')
68
  run_btn = gr.Button('Run', variant='primary')
69
  with gr.Column():
70
+ output_label = gr.Label(label='Model prediction')
71
+ outputs = [output_label]
72
  with gr.Accordion('See video details', open=False):
73
  with gr.Row():
74
  with gr.Column():
75
+ video_embedded1 = gr.HTML(
76
  value=placeholder_youtube_embedded_html)
77
  with gr.Column():
78
  video_embedded2 = gr.HTML(
 
84
  examples_rr = gr.Examples(examples=example_videos_rr, inputs=inputs,
85
  label='Example bad becommendations from the RegretsReporter report')
86
 
87
+ def inputs_change(input, position):
88
+ embedded_value = update_youtube_embedded_html(
89
+ input, position) if input else placeholder_youtube_embedded_html
90
+ if position == 1:
91
+ return {video_embedded1: embedded_value, output_label: None}
92
+ else:
93
+ return {video_embedded2: embedded_value, output_label: None}
94
+
95
  run_btn.click(fn=get_video_similarity, inputs=inputs, outputs=outputs)
96
  clear_btn.click(lambda value_1, value_2, value_3: (
97
  None, None, None), inputs=inputs + outputs, outputs=inputs + outputs)
98
 
99
+ input_text1.change(lambda input: inputs_change(
100
+ input, 1), inputs=input_text1, outputs=[video_embedded1, output_label])
101
+ input_text2.change(lambda input: inputs_change(
102
+ input, 2), inputs=input_text2, outputs=[video_embedded2, output_label])
 
 
 
 
103
 
104
  demo.launch()