Spaces:
Running
Running
Upload 2 files
Browse files- app.py +34 -0
- requirements.txt +24 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import moviepy.editor as mp
|
3 |
+
|
4 |
+
def generate_video_segments(video_path, segment_length=5):
|
5 |
+
"""Splits the video into segments and returns their paths."""
|
6 |
+
video = mp.VideoFileClip(video_path)
|
7 |
+
segment_paths = []
|
8 |
+
|
9 |
+
for i, start in enumerate(range(0, int(video.duration), segment_length)):
|
10 |
+
end = min(start + segment_length, video.duration)
|
11 |
+
segment_clip = video.subclip(start, end)
|
12 |
+
segment_filename = f"segment_{i}.mp4"
|
13 |
+
segment_clip.write_videofile(segment_filename, codec="libx264")
|
14 |
+
segment_paths.append(segment_filename)
|
15 |
+
|
16 |
+
return segment_paths
|
17 |
+
|
18 |
+
def segment_video(file):
|
19 |
+
if file is None:
|
20 |
+
return "No file uploaded.", []
|
21 |
+
|
22 |
+
segments = generate_video_segments(file.name)
|
23 |
+
return "Video segmented successfully!", segments
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("## Video Segmentation Preview")
|
27 |
+
file_input = gr.File(label="Upload Video")
|
28 |
+
segment_button = gr.Button("Generate Segments")
|
29 |
+
output_text = gr.Textbox()
|
30 |
+
video_gallery = gr.Gallery(label="Video Segments") # Displays multiple previews
|
31 |
+
|
32 |
+
segment_button.click(segment_video, inputs=file_input, outputs=[output_text, video_gallery])
|
33 |
+
|
34 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai-whisper
|
2 |
+
sentencepiece
|
3 |
+
SpeechRecognition
|
4 |
+
pydub
|
5 |
+
youtube_transcript_api
|
6 |
+
nltk
|
7 |
+
textblob
|
8 |
+
gradio
|
9 |
+
newspaper3k
|
10 |
+
transformers
|
11 |
+
sentence-transformers
|
12 |
+
openai
|
13 |
+
todoist-api-python
|
14 |
+
flask
|
15 |
+
twilio
|
16 |
+
fastapi
|
17 |
+
uvicorn
|
18 |
+
moviepy
|
19 |
+
ffmpy
|
20 |
+
google-cloud-storage
|
21 |
+
fpdf
|
22 |
+
markdown
|
23 |
+
nest_asyncio
|
24 |
+
reportlab
|