Mathis Petrovich commited on
Commit
6415e78
1 Parent(s): efb0432

All gallery by default, radio or nvids change

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -92,6 +92,8 @@ video {
92
  """
93
 
94
 
 
 
95
  def humanml3d_keyid_to_babel_rendered_url(h3d_index, amass_to_babel, keyid):
96
  # Don't show the mirrored version of HumanMl3D
97
  if "M" in keyid:
@@ -191,6 +193,9 @@ autoplay loop disablepictureinpicture id="{video_id}" title="{title}">
191
 
192
 
193
  def retrieve_component(retrieve_function, text, splits_choice, nvids, n_component=24):
 
 
 
194
  # cannot produce more than n_compoenent
195
  nvids = min(nvids, n_component)
196
 
@@ -207,7 +212,6 @@ def retrieve_component(retrieve_function, text, splits_choice, nvids, n_componen
207
  return htmls
208
 
209
 
210
-
211
  if not os.path.exists("data"):
212
  gdown.download_folder("https://drive.google.com/drive/folders/1MgPFgHZ28AMd01M1tJ7YW_1-ut3-4j08",
213
  use_cookies=False)
@@ -231,8 +235,6 @@ retrieve_function = partial(retrieve, model, keyid_to_url, all_unit_motion_embs,
231
  theme = gr.themes.Default(primary_hue="blue", secondary_hue="gray")
232
  retrieve_and_show = partial(retrieve_component, retrieve_function)
233
 
234
- default_text = "A person is "
235
-
236
  with gr.Blocks(css=CSS, theme=theme) as demo:
237
  gr.Markdown(WEBSITE)
238
  videos = []
@@ -241,18 +243,15 @@ with gr.Blocks(css=CSS, theme=theme) as demo:
241
  with gr.Column(scale=3):
242
  with gr.Column(scale=2):
243
  text = gr.Textbox(placeholder="Type the motion you want to search with a sentence",
244
- show_label=True, label="Text prompt", value=default_text)
245
  with gr.Column(scale=1):
246
  btn = gr.Button("Retrieve", variant='primary')
247
  clear = gr.Button("Clear", variant='secondary')
248
 
249
  with gr.Row():
250
  with gr.Column(scale=1):
251
- # splits = gr.Dropdown(["Train", "Val", "Test"],
252
- # value=["Test"], multiselect=True, label="Splits",
253
- # info="HumanML3D data used for the motion database")
254
- splits_choice = gr.Radio(["Unseen motions", "All motions"], label="Gallery of motion",
255
- value="Unseen motions",
256
  info="The motion gallery is coming from HumanML3D")
257
 
258
  with gr.Column(scale=1):
@@ -300,23 +299,14 @@ with gr.Blocks(css=CSS, theme=theme) as demo:
300
  inputs=examples.inputs,
301
  outputs=videos
302
  )
303
- # def check_error(splits):
304
- # if not splits:
305
- # raise gr.Error("At least one split should be selected!")
306
- # return splits
307
 
308
  btn.click(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
309
- #.then(
310
- # fn=check_error, inputs=splits
311
- # )
312
-
313
  text.submit(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
314
- # .then(
315
- # fn=check_error, inputs=splits
316
- # )
317
 
318
  def clear_videos():
319
- return [None for x in range(24)] + [default_text]
320
 
321
  clear.click(fn=clear_videos, outputs=videos + [text])
322
 
 
92
  """
93
 
94
 
95
+ DEFAULT_TEXT = "A person is "
96
+
97
  def humanml3d_keyid_to_babel_rendered_url(h3d_index, amass_to_babel, keyid):
98
  # Don't show the mirrored version of HumanMl3D
99
  if "M" in keyid:
 
193
 
194
 
195
  def retrieve_component(retrieve_function, text, splits_choice, nvids, n_component=24):
196
+ if text == DEFAULT_TEXT or text == "" or text is None:
197
+ return [None for _ in range(n_component)]
198
+
199
  # cannot produce more than n_compoenent
200
  nvids = min(nvids, n_component)
201
 
 
212
  return htmls
213
 
214
 
 
215
  if not os.path.exists("data"):
216
  gdown.download_folder("https://drive.google.com/drive/folders/1MgPFgHZ28AMd01M1tJ7YW_1-ut3-4j08",
217
  use_cookies=False)
 
235
  theme = gr.themes.Default(primary_hue="blue", secondary_hue="gray")
236
  retrieve_and_show = partial(retrieve_component, retrieve_function)
237
 
 
 
238
  with gr.Blocks(css=CSS, theme=theme) as demo:
239
  gr.Markdown(WEBSITE)
240
  videos = []
 
243
  with gr.Column(scale=3):
244
  with gr.Column(scale=2):
245
  text = gr.Textbox(placeholder="Type the motion you want to search with a sentence",
246
+ show_label=True, label="Text prompt", value=DEFAULT_TEXT)
247
  with gr.Column(scale=1):
248
  btn = gr.Button("Retrieve", variant='primary')
249
  clear = gr.Button("Clear", variant='secondary')
250
 
251
  with gr.Row():
252
  with gr.Column(scale=1):
253
+ splits_choice = gr.Radio(["All motions", "Unseen motions"], label="Gallery of motion",
254
+ value="All motions",
 
 
 
255
  info="The motion gallery is coming from HumanML3D")
256
 
257
  with gr.Column(scale=1):
 
299
  inputs=examples.inputs,
300
  outputs=videos
301
  )
 
 
 
 
302
 
303
  btn.click(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
 
 
 
 
304
  text.submit(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
305
+ splits_choice.change(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
306
+ nvideo_slider.change(fn=retrieve_and_show, inputs=[text, splits_choice, nvideo_slider], outputs=videos)
 
307
 
308
  def clear_videos():
309
+ return [None for x in range(24)] + [DEFAULT_TEXT]
310
 
311
  clear.click(fn=clear_videos, outputs=videos + [text])
312