Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from datetime import datetime
|
3 |
import random
|
|
|
4 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
5 |
from moviepy import (
|
6 |
ImageClip,
|
@@ -11,25 +12,41 @@ from moviepy import (
|
|
11 |
concatenate_videoclips
|
12 |
)
|
13 |
|
|
|
|
|
|
|
|
|
14 |
def generate_video_segments(video_path, segment_length=5):
|
15 |
"""Splits the video into segments and returns their paths."""
|
16 |
video = VideoFileClip(video_path)
|
17 |
segment_paths = []
|
18 |
|
|
|
|
|
19 |
for i, start in enumerate(range(0, int(video.duration), segment_length)):
|
20 |
end = min(start + segment_length, video.duration)
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
return segment_paths
|
27 |
|
28 |
def segment_video(file):
|
29 |
if file is None:
|
|
|
30 |
return "No file uploaded.", []
|
31 |
|
|
|
32 |
segments = generate_video_segments(file.name)
|
|
|
33 |
return "Video segmented successfully!", segments
|
34 |
|
35 |
with gr.Blocks() as demo:
|
@@ -41,4 +58,4 @@ with gr.Blocks() as demo:
|
|
41 |
|
42 |
segment_button.click(segment_video, inputs=file_input, outputs=[output_text, video_gallery])
|
43 |
|
44 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from datetime import datetime
|
3 |
import random
|
4 |
+
import logging
|
5 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
6 |
from moviepy import (
|
7 |
ImageClip,
|
|
|
12 |
concatenate_videoclips
|
13 |
)
|
14 |
|
15 |
+
# Set up logging
|
16 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
|
17 |
+
logger = logging.getLogger()
|
18 |
+
|
19 |
def generate_video_segments(video_path, segment_length=5):
|
20 |
"""Splits the video into segments and returns their paths."""
|
21 |
video = VideoFileClip(video_path)
|
22 |
segment_paths = []
|
23 |
|
24 |
+
logger.info(f"Video duration: {video.duration} seconds.")
|
25 |
+
|
26 |
for i, start in enumerate(range(0, int(video.duration), segment_length)):
|
27 |
end = min(start + segment_length, video.duration)
|
28 |
+
logger.info(f"Processing segment {i}: Start time = {start}s, End time = {end}s")
|
29 |
+
|
30 |
+
try:
|
31 |
+
segment_clip = video.subclip(start, end)
|
32 |
+
segment_filename = f"segment_{i}.mp4"
|
33 |
+
logger.info(f"Writing segment {i} to file: {segment_filename}")
|
34 |
+
segment_clip.write_videofile(segment_filename, codec="libx264")
|
35 |
+
segment_paths.append(segment_filename)
|
36 |
+
except Exception as e:
|
37 |
+
logger.error(f"Error in processing segment {i}: {str(e)}")
|
38 |
+
|
39 |
+
logger.info(f"Total segments generated: {len(segment_paths)}")
|
40 |
return segment_paths
|
41 |
|
42 |
def segment_video(file):
|
43 |
if file is None:
|
44 |
+
logger.error("No file uploaded.")
|
45 |
return "No file uploaded.", []
|
46 |
|
47 |
+
logger.info("Starting video segmentation.")
|
48 |
segments = generate_video_segments(file.name)
|
49 |
+
logger.info("Video segmentation complete.")
|
50 |
return "Video segmented successfully!", segments
|
51 |
|
52 |
with gr.Blocks() as demo:
|
|
|
58 |
|
59 |
segment_button.click(segment_video, inputs=file_input, outputs=[output_text, video_gallery])
|
60 |
|
61 |
+
demo.launch()
|