Spaces:
Runtime error
Runtime error
chore: handle empty video
Browse files
app.py
CHANGED
@@ -22,11 +22,11 @@ def trim_video(video_path, start, end, output_file='result.mp4'):
|
|
22 |
return output_file
|
23 |
|
24 |
def display_prediction(result):
|
25 |
-
return f'Moment
|
26 |
|
27 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
28 |
-
output_videos = gr.State(
|
29 |
-
moment_prediction = gr.State(
|
30 |
gr.HTML("""<h2 align="center"> 🎞️ Highlight Detection with MomentDETR </h2>""")
|
31 |
gr.Markdown(DESCRIPTION)
|
32 |
with gr.Column():
|
@@ -46,16 +46,18 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
46 |
placeholder="What should be highlighted?",
|
47 |
visible=True
|
48 |
)
|
49 |
-
submit =gr.Button("Submit")
|
50 |
with gr.Column():
|
51 |
-
display_score = gr.Markdown("### Moment Score: ")
|
52 |
radio_button = gr.Radio(
|
53 |
choices=[i+1 for i in range(10)],
|
54 |
label="Moments",
|
55 |
value=1
|
56 |
)
|
|
|
57 |
|
58 |
def update_video_player(radio_value, output_videos, moment_prediction):
|
|
|
|
|
59 |
return {
|
60 |
playable_video: output_videos[radio_value-1],
|
61 |
display_score: display_prediction(moment_prediction[radio_value-1])
|
@@ -64,6 +66,8 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
64 |
def submit_video(input_video, retrieval_text):
|
65 |
print(f'== video path: {input_video}')
|
66 |
print(f'== retrieval_text: {retrieval_text}')
|
|
|
|
|
67 |
if retrieval_text is None:
|
68 |
retrieval_text = ''
|
69 |
predictions, video_frames = moment_detr_predictor.localize_moment(
|
@@ -83,7 +87,8 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
83 |
output_videos: output_files,
|
84 |
moment_prediction: predictions,
|
85 |
playable_video: output_files[0],
|
86 |
-
display_score: display_prediction(predictions[0])
|
|
|
87 |
}
|
88 |
|
89 |
radio_button.change(
|
@@ -95,7 +100,7 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
95 |
submit.click(
|
96 |
fn=submit_video,
|
97 |
inputs=[input_video, retrieval_text],
|
98 |
-
outputs=[output_videos, moment_prediction, playable_video, display_score]
|
99 |
)
|
100 |
|
101 |
demo.launch()
|
|
|
22 |
return output_file
|
23 |
|
24 |
def display_prediction(result):
|
25 |
+
return f'### Moment Start time: {result[0]}, End time: {result[1]}, Score: {result[2]}'
|
26 |
|
27 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
28 |
+
output_videos = gr.State(None)
|
29 |
+
moment_prediction = gr.State(None)
|
30 |
gr.HTML("""<h2 align="center"> 🎞️ Highlight Detection with MomentDETR </h2>""")
|
31 |
gr.Markdown(DESCRIPTION)
|
32 |
with gr.Column():
|
|
|
46 |
placeholder="What should be highlighted?",
|
47 |
visible=True
|
48 |
)
|
49 |
+
submit = gr.Button("Submit")
|
50 |
with gr.Column():
|
|
|
51 |
radio_button = gr.Radio(
|
52 |
choices=[i+1 for i in range(10)],
|
53 |
label="Moments",
|
54 |
value=1
|
55 |
)
|
56 |
+
display_score = gr.Markdown("### Moment Score: ")
|
57 |
|
58 |
def update_video_player(radio_value, output_videos, moment_prediction):
|
59 |
+
if output_videos is None or moment_prediction is None:
|
60 |
+
return [None, None]
|
61 |
return {
|
62 |
playable_video: output_videos[radio_value-1],
|
63 |
display_score: display_prediction(moment_prediction[radio_value-1])
|
|
|
66 |
def submit_video(input_video, retrieval_text):
|
67 |
print(f'== video path: {input_video}')
|
68 |
print(f'== retrieval_text: {retrieval_text}')
|
69 |
+
if input_video is None:
|
70 |
+
return [None, None, None, None, 1]
|
71 |
if retrieval_text is None:
|
72 |
retrieval_text = ''
|
73 |
predictions, video_frames = moment_detr_predictor.localize_moment(
|
|
|
87 |
output_videos: output_files,
|
88 |
moment_prediction: predictions,
|
89 |
playable_video: output_files[0],
|
90 |
+
display_score: display_prediction(predictions[0]),
|
91 |
+
radio_button: 1
|
92 |
}
|
93 |
|
94 |
radio_button.change(
|
|
|
100 |
submit.click(
|
101 |
fn=submit_video,
|
102 |
inputs=[input_video, retrieval_text],
|
103 |
+
outputs=[output_videos, moment_prediction, playable_video, display_score, radio_button]
|
104 |
)
|
105 |
|
106 |
demo.launch()
|