Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
-
def
|
5 |
if video_file is None:
|
6 |
return None, "No video uploaded."
|
7 |
|
8 |
-
# Check if the uploaded file is a valid binary file
|
9 |
try:
|
10 |
-
if len(video_file) > 0:
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
else:
|
13 |
return None, "Uploaded file is empty."
|
14 |
except Exception as e:
|
@@ -16,12 +19,12 @@ def display_video(video_file):
|
|
16 |
|
17 |
with gr.Blocks() as demo:
|
18 |
with gr.Column():
|
19 |
-
video_file = gr.File(label="Upload Video File", type="binary", file_types=["mp4", "avi", "
|
20 |
output_video = gr.Video()
|
21 |
output_message = gr.Textbox(label="Output Message")
|
22 |
submit_button = gr.Button("Display Video")
|
23 |
submit_button.click(
|
24 |
-
fn=
|
25 |
inputs=video_file,
|
26 |
outputs=[output_video, output_message]
|
27 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
+
def save_and_display_video(video_file):
|
5 |
if video_file is None:
|
6 |
return None, "No video uploaded."
|
7 |
|
|
|
8 |
try:
|
9 |
+
if len(video_file) > 0:
|
10 |
+
# Save the binary content to a file
|
11 |
+
file_path = 'uploaded_video.mp4' # Assuming .mp4 for simplicity
|
12 |
+
with open(file_path, 'wb') as f:
|
13 |
+
f.write(video_file)
|
14 |
+
return file_path, "Video uploaded and displayed successfully."
|
15 |
else:
|
16 |
return None, "Uploaded file is empty."
|
17 |
except Exception as e:
|
|
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
with gr.Column():
|
22 |
+
video_file = gr.File(label="Upload Video File", type="binary", file_types=["mp4", "avi", "move"], interactive=True)
|
23 |
output_video = gr.Video()
|
24 |
output_message = gr.Textbox(label="Output Message")
|
25 |
submit_button = gr.Button("Display Video")
|
26 |
submit_button.click(
|
27 |
+
fn=save_and_display_video,
|
28 |
inputs=video_file,
|
29 |
outputs=[output_video, output_message]
|
30 |
)
|