Update app.py
Browse files
app.py
CHANGED
@@ -16,18 +16,26 @@ import ffmpeg
|
|
16 |
import nltk
|
17 |
nltk.download('averaged_perceptron_tagger_eng')
|
18 |
|
19 |
-
def
|
20 |
if language_choice == None:
|
21 |
return None, "Language not selected."
|
22 |
-
elif video_file == None
|
23 |
-
return None, "
|
24 |
-
|
25 |
-
return
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
yt = YouTube(youtube_url)
|
28 |
yt.streams.filter(progressive=True, file_extension='mp4').first().download(filename="original.mp4")
|
29 |
video_file = "original.mp4"
|
30 |
-
|
|
|
|
|
31 |
# Initialize paths and devices
|
32 |
ckpt_converter = 'checkpoints_v2/converter'
|
33 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
@@ -266,11 +274,10 @@ def process_video(video_file, youtube_url, language_choice):
|
|
266 |
language_choices = ts.get_languages("google")["en"]
|
267 |
language_choices.remove("auto")
|
268 |
|
269 |
-
gr.Interface(
|
270 |
-
fn=
|
271 |
inputs=[
|
272 |
gr.Video(label="Upload a video from your device storage", sources=['upload']),
|
273 |
-
gr.Textbox(label="OR enter a YouTube video URL"),
|
274 |
gr.Dropdown(choices=language_choices, label="Choose Language for Translation (Expressed in ISO 639-1 code)")
|
275 |
],
|
276 |
outputs=[
|
@@ -279,4 +286,20 @@ gr.Interface(
|
|
279 |
],
|
280 |
title="Video Translation and Voice Cloning",
|
281 |
description="Upload a video, choose a language to translate the audio, and download the processed video with translated audio."
|
282 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
import nltk
|
17 |
nltk.download('averaged_perceptron_tagger_eng')
|
18 |
|
19 |
+
def process_upload(video_file, language_choice):
|
20 |
if language_choice == None:
|
21 |
return None, "Language not selected."
|
22 |
+
elif video_file == None:
|
23 |
+
return None, "Video not uploaded."
|
24 |
+
else:
|
25 |
+
return process_video(video_file, language_choice)
|
26 |
+
|
27 |
+
def process_youtube(youtube_url, language_choice):
|
28 |
+
if language_choice == None:
|
29 |
+
return None, "Language not selected."
|
30 |
+
elif youtube_url == None:
|
31 |
+
return None, "YouTube URL not entered."
|
32 |
+
else:
|
33 |
yt = YouTube(youtube_url)
|
34 |
yt.streams.filter(progressive=True, file_extension='mp4').first().download(filename="original.mp4")
|
35 |
video_file = "original.mp4"
|
36 |
+
return process_video(video_file, language_choice)
|
37 |
+
|
38 |
+
def process_video(video_file, language_choice):
|
39 |
# Initialize paths and devices
|
40 |
ckpt_converter = 'checkpoints_v2/converter'
|
41 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
274 |
language_choices = ts.get_languages("google")["en"]
|
275 |
language_choices.remove("auto")
|
276 |
|
277 |
+
uploaded_translator = gr.Interface(
|
278 |
+
fn=process_upload,
|
279 |
inputs=[
|
280 |
gr.Video(label="Upload a video from your device storage", sources=['upload']),
|
|
|
281 |
gr.Dropdown(choices=language_choices, label="Choose Language for Translation (Expressed in ISO 639-1 code)")
|
282 |
],
|
283 |
outputs=[
|
|
|
286 |
],
|
287 |
title="Video Translation and Voice Cloning",
|
288 |
description="Upload a video, choose a language to translate the audio, and download the processed video with translated audio."
|
289 |
+
)
|
290 |
+
|
291 |
+
youtube_translator = gr.Interface(
|
292 |
+
fn=process_youtube,
|
293 |
+
inputs=[
|
294 |
+
gr.Textbox(label="Enter a YouTube video URL"),
|
295 |
+
gr.Dropdown(choices=language_choices, label="Choose Language for Translation (Expressed in ISO 639-1 code)")
|
296 |
+
],
|
297 |
+
outputs=[
|
298 |
+
gr.Video(label="Translated Video", format='mp4'),
|
299 |
+
gr.Textbox(show_label=False)
|
300 |
+
],
|
301 |
+
title="Video Translation and Voice Cloning",
|
302 |
+
description="Upload a video, choose a language to translate the audio, and download the processed video with translated audio."
|
303 |
+
)
|
304 |
+
|
305 |
+
gr.TabbedInterface([uploaded_translator, youtube_translator], ["Upload video from device", "YouTube URL"]).launch()
|