dylan-plummer commited on
Commit
bc7bea1
·
1 Parent(s): f13d8aa

add video display

Browse files
Files changed (1) hide show
  1. app.py +14 -38
app.py CHANGED
@@ -328,7 +328,7 @@ def inference(stream_url, start_time, end_time, count_only_api, api_key,
328
  labels={'x': 'event type', 'y': 'probability'},
329
  range_y=[0, 1])
330
 
331
- return count_msg, fig, hist, bar
332
 
333
 
334
  DESCRIPTION = '# NextJump 🦘'
@@ -343,8 +343,12 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
343
  # max_length=150)
344
  with gr.Row():
345
  in_stream_url = gr.Textbox(label="Stream URL", elem_id='stream-url', visible=True)
346
- in_stream_start = gr.Textbox(label="Start Time", elem_id='stream-start', visible=True)
347
- in_stream_end = gr.Textbox(label="End Time", elem_id='stream-end', visible=True)
 
 
 
 
348
 
349
  with gr.Row():
350
  run_button = gr.Button(value="Run", elem_id='run-button', scale=1)
@@ -358,8 +362,6 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
358
  out_text = gr.Markdown(label="Predicted Count", elem_id='output-text')
359
  period_length = gr.Textbox(label="Period Length", elem_id='period-length', visible=False)
360
  periodicity = gr.Textbox(label="Periodicity", elem_id='periodicity', visible=False)
361
- #with gr.Column(min_width=480):
362
- #out_video = gr.PlayableVideo(label="Output Video", elem_id='output-video', format='mp4')
363
  with gr.Row():
364
  out_plot = gr.Plot(label="Jumping Speed", elem_id='output-plot')
365
  with gr.Row():
@@ -368,21 +370,6 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
368
  with gr.Column():
369
  out_event_type_dist = gr.Plot(label="Event Type Distribution", elem_id='output-event-type-dist')
370
 
371
- with gr.Accordion(label="Instructions and more information", open=False):
372
- instructions = "## Instructions:"
373
- instructions += "\n* Upload a video and click 'Run' to get a prediction of the number of jumps (either one foot, or both). This could take a couple minutes!"
374
- instructions += "\n\n## Tips (optional):"
375
- instructions += "\n* Trim the video to start and end of the event"
376
- instructions += "\n* Frame the jumper fully, in the center of the frame"
377
- instructions += "\n* Videos are automatically resized, so higher resolution will not help, but a closer framing of the jumper might help. Try cropping the video differently."
378
- gr.Markdown(instructions)
379
-
380
- faq = "## FAQ:"
381
- faq += "\n* **Q:** Does the model recognize misses?\n * **A:** Yes, but if it fails, you can try tuning the miss threshold slider to make it more sensitive."
382
- faq += "\n* **Q:** Does the model recognize double dutch?\n * **A:** Yes, but it is trained on a smaller set of double dutch videos, so it may not work perfectly."
383
- faq += "\n* **Q:** Does the model recognize double unders\n * **A:** Yes, but it is trained on a smaller set of double under videos, so it may not work perfectly. It is also trained to count the rope, not the jumps so you will need to divide the count by 2 to get the traditional double under count."
384
- faq += "\n* **Q:** Does the model count both feet?\n * **A:** Yes, it counts every time the rope goes around no matter the event."
385
- gr.Markdown(faq)
386
 
387
  demo_inference = partial(inference, count_only_api=False, api_key=None)
388
 
@@ -397,25 +384,14 @@ with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
397
  # f"{playlist_url}rec_rd2FAyUo/vod",
398
  # ]
399
 
400
- gr.Examples(examples=[
401
- ['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_rd2FAyUo/vod', '00:43:10', '00:43:40'],
402
- #[os.path.join(os.path.dirname(__file__), "files", "train14.mp4")],
403
- #[os.path.join(os.path.dirname(__file__), "files", "train_17.mp4")],
404
- #[os.path.join(os.path.dirname(__file__), "files", "train13.mp4")],
405
- #[os.path.join(os.path.dirname(__file__), "files", "train_213.mp4")],
406
- #[os.path.join(os.path.dirname(__file__), "files", "train_156.mp4")],
407
- #[os.path.join(os.path.dirname(__file__), "files", "train_202.mp4")],
408
- #[os.path.join(os.path.dirname(__file__), "files", "train_57.mp4")],
409
- #[os.path.join(os.path.dirname(__file__), "files", "train_95.mp4")],
410
- #[os.path.join(os.path.dirname(__file__), "files", "train_253.mp4")],
411
- #[os.path.join(os.path.dirname(__file__), "files", "train_66.mp4")],
412
- #[os.path.join(os.path.dirname(__file__), "files", "train_21.mp4")]
413
- ],
414
- inputs=[in_stream_url, in_stream_start, in_stream_end],
415
- outputs=[out_text, out_plot, out_hist, out_event_type_dist],
416
- fn=demo_inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
417
 
418
- run_button.click(demo_inference, [in_stream_url, in_stream_start, in_stream_end], outputs=[out_text, out_plot, out_hist, out_event_type_dist])
419
  api_inference = partial(inference, api_call=True)
420
  api_dummy_button.click(api_inference, [in_stream_url, in_stream_start, in_stream_end, count_only, api_token], outputs=[period_length], api_name='inference')
421
 
 
328
  labels={'x': 'event type', 'y': 'probability'},
329
  range_y=[0, 1])
330
 
331
+ return x, count_msg, fig, hist, bar
332
 
333
 
334
  DESCRIPTION = '# NextJump 🦘'
 
343
  # max_length=150)
344
  with gr.Row():
345
  in_stream_url = gr.Textbox(label="Stream URL", elem_id='stream-url', visible=True)
346
+ with gr.Column():
347
+ in_stream_start = gr.Textbox(label="Start Time", elem_id='stream-start', visible=True)
348
+ with gr.Column():
349
+ in_stream_end = gr.Textbox(label="End Time", elem_id='stream-end', visible=True)
350
+ with gr.Column(min_width=480):
351
+ out_video = gr.PlayableVideo(label="Video Clip", elem_id='output-video', format='mp4', width=400, height=400)
352
 
353
  with gr.Row():
354
  run_button = gr.Button(value="Run", elem_id='run-button', scale=1)
 
362
  out_text = gr.Markdown(label="Predicted Count", elem_id='output-text')
363
  period_length = gr.Textbox(label="Period Length", elem_id='period-length', visible=False)
364
  periodicity = gr.Textbox(label="Periodicity", elem_id='periodicity', visible=False)
 
 
365
  with gr.Row():
366
  out_plot = gr.Plot(label="Jumping Speed", elem_id='output-plot')
367
  with gr.Row():
 
370
  with gr.Column():
371
  out_event_type_dist = gr.Plot(label="Event Type Distribution", elem_id='output-event-type-dist')
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
374
  demo_inference = partial(inference, count_only_api=False, api_key=None)
375
 
 
384
  # f"{playlist_url}rec_rd2FAyUo/vod",
385
  # ]
386
 
387
+ # gr.Examples(examples=[
388
+ # ['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_rd2FAyUo/vod', '00:43:10', '00:43:40'],
389
+ # ],
390
+ # inputs=[in_stream_url, in_stream_start, in_stream_end],
391
+ # outputs=[out_text, out_plot, out_hist, out_event_type_dist],
392
+ # fn=demo_inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
 
 
 
 
 
 
 
 
 
 
 
393
 
394
+ run_button.click(demo_inference, [in_stream_url, in_stream_start, in_stream_end], outputs=[out_video, out_text, out_plot, out_hist, out_event_type_dist])
395
  api_inference = partial(inference, api_call=True)
396
  api_dummy_button.click(api_inference, [in_stream_url, in_stream_start, in_stream_end, count_only, api_token], outputs=[period_length], api_name='inference')
397