Spaces:
Runtime error
Runtime error
bug fix, video input and output
#12
by Banuka - opened
app.py
CHANGED
|
@@ -1,8 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
|
| 5 |
def predict_video(input_video, input_audio=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
Processes the uploaded video (replace with your video analysis logic).
|
| 8 |
|
|
@@ -45,15 +60,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 45 |
</p>
|
| 46 |
""")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
gr.Examples(
|
| 59 |
examples=[[os.path.join(os.path.dirname(__file__), "video/test_video.mp4"),
|
|
@@ -66,10 +81,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 66 |
|
| 67 |
video_in.change(
|
| 68 |
fn=predict_video,
|
| 69 |
-
inputs=[audio_in],
|
| 70 |
outputs=[video_out, text_out],
|
| 71 |
queue=False
|
| 72 |
-
|
| 73 |
|
| 74 |
|
| 75 |
demo.launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
|
|
|
| 4 |
def predict_video(input_video, input_audio=None):
|
| 5 |
+
global filename, file_size # Use the global keyword to refer to the global variables
|
| 6 |
+
|
| 7 |
+
# Check if the video is available
|
| 8 |
+
if input_video is None:
|
| 9 |
+
return [None, "Please upload a video"]
|
| 10 |
+
|
| 11 |
+
filename = input_video.name # Get the uploaded filename
|
| 12 |
+
file_size = os.path.getsize(input_video.name) # Get the file size in bytes
|
| 13 |
+
|
| 14 |
+
# Loop until a valid video is uploaded
|
| 15 |
+
if not filename.lower().endswith('.mp4'):
|
| 16 |
+
return [None, "Error: Please upload an MP4 video file."]
|
| 17 |
+
|
| 18 |
+
if file_size > 16 * 1024 * 1024:
|
| 19 |
+
return [None, "Error: The upload exceeds file size 16MB. Please upload a smaller file."]
|
| 20 |
+
|
| 21 |
"""
|
| 22 |
Processes the uploaded video (replace with your video analysis logic).
|
| 23 |
|
|
|
|
| 60 |
</p>
|
| 61 |
""")
|
| 62 |
|
| 63 |
+
with gr.Row():
|
| 64 |
+
with gr.Column():
|
| 65 |
+
video_in = gr.File(label="Upload a Video", file_types=[".mp4"])
|
| 66 |
+
with gr.Column():
|
| 67 |
+
audio_in = gr.File(label="Optional: Upload an Audio Track", file_types=[".mp3"])
|
| 68 |
+
with gr.Column():
|
| 69 |
+
video_out = gr.Video(label="Output Video")
|
| 70 |
+
with gr.Row():
|
| 71 |
+
text_out = gr.Textbox(label="Output Text")
|
| 72 |
|
| 73 |
gr.Examples(
|
| 74 |
examples=[[os.path.join(os.path.dirname(__file__), "video/test_video.mp4"),
|
|
|
|
| 81 |
|
| 82 |
video_in.change(
|
| 83 |
fn=predict_video,
|
| 84 |
+
inputs=[video_in, audio_in], # Use both video and audio inputs here
|
| 85 |
outputs=[video_out, text_out],
|
| 86 |
queue=False
|
| 87 |
+
)
|
| 88 |
|
| 89 |
|
| 90 |
demo.launch(debug=True)
|