Commit ·
210bfb4
1
Parent(s): 2777f96
add video upload option
Browse files
app.py
CHANGED
|
@@ -117,13 +117,16 @@ def detect_beeps(video_path, event_length=30, beep_height=0.8):
|
|
| 117 |
return event_start, event_end
|
| 118 |
|
| 119 |
|
| 120 |
-
def inference(stream_url, start_time, end_time, beep_detection_on, event_length, count_only_api, api_key,
|
| 121 |
img_size=256, seq_len=64, stride_length=32, stride_pad=3, batch_size=4,
|
| 122 |
miss_threshold=0.8, marks_threshold=0.5, median_pred_filter=True, both_feet=True,
|
| 123 |
api_call=False,
|
| 124 |
progress=gr.Progress()):
|
| 125 |
progress(0, desc="Downloading clip...")
|
| 126 |
-
in_video
|
|
|
|
|
|
|
|
|
|
| 127 |
progress(0, desc="Running inference...")
|
| 128 |
has_access = False
|
| 129 |
if api_call:
|
|
@@ -406,10 +409,15 @@ def inference(stream_url, start_time, end_time, beep_detection_on, event_length,
|
|
| 406 |
|
| 407 |
|
| 408 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
with gr.Row():
|
| 410 |
with gr.Column():
|
| 411 |
in_stream_url = gr.Textbox(label="Stream URL", elem_id='stream-url', visible=True)
|
| 412 |
-
|
|
|
|
| 413 |
in_stream_end = gr.Textbox(label="End Time", elem_id='stream-end', visible=True)
|
| 414 |
with gr.Column():
|
| 415 |
beep_detection_on = gr.Checkbox(label="Detect Beeps", elem_id='detect-beeps', visible=True)
|
|
@@ -440,19 +448,19 @@ with gr.Blocks() as demo:
|
|
| 440 |
|
| 441 |
demo_inference = partial(inference, count_only_api=False, api_key=None)
|
| 442 |
|
| 443 |
-
run_button.click(demo_inference, [in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length],
|
| 444 |
outputs=[out_video, out_text, out_plot, out_hist, out_event_type_dist])
|
| 445 |
api_inference = partial(inference, api_call=True)
|
| 446 |
-
api_dummy_button.click(api_inference, [in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length, count_only, api_token],
|
| 447 |
outputs=[period_length], api_name='inference')
|
| 448 |
examples = [
|
| 449 |
#['https://hiemdall-dev2.azurewebsites.net/api/clip/clp_vrpWTyjM/mp4', '00:00:00', '00:01:10', True, 60],
|
| 450 |
-
['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_UGEhqlMh/vod', '00:00:18', '00:00:55', True, 30],
|
| 451 |
#['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_rd2FAyUo/vod', '01:24:22', '01:25:35', True, 60]
|
| 452 |
#['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_PY5Ukaua/vod, '00:52:53', '00:55:00', True, 120]
|
| 453 |
]
|
| 454 |
gr.Examples(examples,
|
| 455 |
-
inputs=[in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length],
|
| 456 |
outputs=[out_video, out_text, out_plot, out_hist, out_event_type_dist],
|
| 457 |
fn=demo_inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
|
| 458 |
|
|
|
|
| 117 |
return event_start, event_end
|
| 118 |
|
| 119 |
|
| 120 |
+
def inference(in_video, stream_url, start_time, end_time, beep_detection_on, event_length, count_only_api, api_key,
|
| 121 |
img_size=256, seq_len=64, stride_length=32, stride_pad=3, batch_size=4,
|
| 122 |
miss_threshold=0.8, marks_threshold=0.5, median_pred_filter=True, both_feet=True,
|
| 123 |
api_call=False,
|
| 124 |
progress=gr.Progress()):
|
| 125 |
progress(0, desc="Downloading clip...")
|
| 126 |
+
if in_video is None:
|
| 127 |
+
in_video = download_clips(stream_url, os.path.join(os.getcwd(), 'clips'), start_time, end_time)
|
| 128 |
+
else: # local uploaded video (still resize with ffmpeg)
|
| 129 |
+
in_video = download_clips(in_video, os.path.join(os.getcwd(), 'clips'), start_time, end_time)
|
| 130 |
progress(0, desc="Running inference...")
|
| 131 |
has_access = False
|
| 132 |
if api_call:
|
|
|
|
| 409 |
|
| 410 |
|
| 411 |
with gr.Blocks() as demo:
|
| 412 |
+
with gr.Row():
|
| 413 |
+
in_video = gr.PlayableVideo(label="Input Video", elem_id='input-video', format='mp4',
|
| 414 |
+
width=400, height=400, interactive=True, container=True,
|
| 415 |
+
max_length=300)
|
| 416 |
with gr.Row():
|
| 417 |
with gr.Column():
|
| 418 |
in_stream_url = gr.Textbox(label="Stream URL", elem_id='stream-url', visible=True)
|
| 419 |
+
|
| 420 |
+
in_stream_start = gr.Textbox(label="Start Time", elem_id='stream-start', visible=True, value='00:00:00')
|
| 421 |
in_stream_end = gr.Textbox(label="End Time", elem_id='stream-end', visible=True)
|
| 422 |
with gr.Column():
|
| 423 |
beep_detection_on = gr.Checkbox(label="Detect Beeps", elem_id='detect-beeps', visible=True)
|
|
|
|
| 448 |
|
| 449 |
demo_inference = partial(inference, count_only_api=False, api_key=None)
|
| 450 |
|
| 451 |
+
run_button.click(demo_inference, [in_video, in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length],
|
| 452 |
outputs=[out_video, out_text, out_plot, out_hist, out_event_type_dist])
|
| 453 |
api_inference = partial(inference, api_call=True)
|
| 454 |
+
api_dummy_button.click(api_inference, [in_video, in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length, count_only, api_token],
|
| 455 |
outputs=[period_length], api_name='inference')
|
| 456 |
examples = [
|
| 457 |
#['https://hiemdall-dev2.azurewebsites.net/api/clip/clp_vrpWTyjM/mp4', '00:00:00', '00:01:10', True, 60],
|
| 458 |
+
[None, 'https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_UGEhqlMh/vod', '00:00:18', '00:00:55', True, 30],
|
| 459 |
#['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_rd2FAyUo/vod', '01:24:22', '01:25:35', True, 60]
|
| 460 |
#['https://hiemdall-dev2.azurewebsites.net/api/playlist/rec_PY5Ukaua/vod, '00:52:53', '00:55:00', True, 120]
|
| 461 |
]
|
| 462 |
gr.Examples(examples,
|
| 463 |
+
inputs=[in_video, in_stream_url, in_stream_start, in_stream_end, beep_detection_on, event_length],
|
| 464 |
outputs=[out_video, out_text, out_plot, out_hist, out_event_type_dist],
|
| 465 |
fn=demo_inference, cache_examples=os.getenv('SYSTEM') == 'spaces')
|
| 466 |
|