Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,10 @@ from modeler import SfM
|
|
3 |
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
4 |
from pytube import YouTube
|
5 |
import uuid
|
|
|
6 |
uid=uuid.uuid4()
|
7 |
-
|
|
|
8 |
def load_video_yt(vid):
|
9 |
yt = YouTube(vid)
|
10 |
vid = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=f"{uid}-tmp.mp4")
|
@@ -25,26 +27,12 @@ def trim_vid(vid,start_time,end_time):
|
|
25 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
26 |
return f"{uid}-clip.mp4"
|
27 |
|
28 |
-
def trim_clip(clip, start_t, end_t):
|
29 |
-
clip = Path(f"{uid}-tmp_aud.mp4")
|
30 |
-
song = AudioSegment.from_file(f"{uid}-tmp_aud.mp4", format="mp4")
|
31 |
-
start_min = int(start_t.split(":",1)[0])
|
32 |
-
start_sec = int(start_t.split(":",1)[1])
|
33 |
-
end_min = int(end_t.split(":",1)[0])
|
34 |
-
end_sec = int(end_t.split(":",1)[1])
|
35 |
-
start = ((start_min*60)+start_sec)*1000
|
36 |
-
end = ((end_min*60)+end_sec)*1000
|
37 |
-
song_clip = song[start: end]
|
38 |
-
song_clip.export(f"{uid}-trim.wav", format="wav")
|
39 |
-
print("New Audio file is created and saved")
|
40 |
-
|
41 |
-
return f"{uid}-trim.wav"
|
42 |
-
|
43 |
|
44 |
def make_model(vid_path):
|
45 |
-
sfm = SfM('
|
46 |
sfm.structure_from_motion()
|
47 |
-
|
|
|
48 |
with gr.Blocks() as app:
|
49 |
with gr.Row():
|
50 |
inp_url=gr.Textbox(label="URL")
|
@@ -56,7 +44,9 @@ with gr.Blocks() as app:
|
|
56 |
start_time = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23")
|
57 |
end_time = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
|
58 |
trim_clip_btn = gr.Button("Trim Clip")
|
|
|
59 |
out=gr.Files()
|
|
|
60 |
load_yt_btn.click(load_video_yt, inp_url, [pre_vid])
|
61 |
trim_clip_btn.click(trim_vid,[pre_vid,start_time,end_time],clip_vid)
|
62 |
app.launch()
|
|
|
3 |
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
4 |
from pytube import YouTube
|
5 |
import uuid
|
6 |
+
import os
|
7 |
uid=uuid.uuid4()
|
8 |
+
if not os.path.exists(f'{uid}'):
|
9 |
+
os.makedirs(f'{uid}')
|
10 |
def load_video_yt(vid):
|
11 |
yt = YouTube(vid)
|
12 |
vid = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=f"{uid}-tmp.mp4")
|
|
|
27 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
28 |
return f"{uid}-clip.mp4"
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def make_model(vid_path):
|
32 |
+
sfm = SfM(f'{uid}/', False, f'{uid}-clip.mp4', 27)
|
33 |
sfm.structure_from_motion()
|
34 |
+
return f'{uid}/'
|
35 |
+
|
36 |
with gr.Blocks() as app:
|
37 |
with gr.Row():
|
38 |
inp_url=gr.Textbox(label="URL")
|
|
|
44 |
start_time = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23")
|
45 |
end_time = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
|
46 |
trim_clip_btn = gr.Button("Trim Clip")
|
47 |
+
make_btn=gr.Button()
|
48 |
out=gr.Files()
|
49 |
+
make_btn.click(make_model,clip_vid,out)
|
50 |
load_yt_btn.click(load_video_yt, inp_url, [pre_vid])
|
51 |
trim_clip_btn.click(trim_vid,[pre_vid,start_time,end_time],clip_vid)
|
52 |
app.launch()
|