Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
|
6 |
# importing all necessary libraries
|
7 |
import httpcore
|
8 |
-
setattr(httpcore, 'SyncHTTPTransport', 'AsyncHTTPProxy')
|
9 |
import pathlib
|
10 |
import sys, os
|
11 |
from gtts import gTTS
|
@@ -39,7 +38,7 @@ def validate_youtube(url):
|
|
39 |
return True
|
40 |
#This will return the length of the video in sec as an int
|
41 |
video_length = yt.length
|
42 |
-
if
|
43 |
print("Your video is larger than 10 minutes")
|
44 |
return True
|
45 |
else:
|
@@ -72,7 +71,7 @@ def cleanup():
|
|
72 |
# Calling the unlink method on the path
|
73 |
file.unlink()
|
74 |
except Exception:
|
75 |
-
print("I cannot delete the file because it is being used by another process")
|
76 |
|
77 |
def getSize(filename):
|
78 |
st = os.stat(filename)
|
@@ -94,7 +93,7 @@ def clean_transcript(transcript_list):
|
|
94 |
(t != '[música]') and \
|
95 |
(t != '[Música]') and \
|
96 |
(t != '[音楽]') and \
|
97 |
-
(t != '[音乐]')
|
98 |
) :
|
99 |
script += t + " "
|
100 |
return script
|
@@ -120,7 +119,7 @@ def get_transcript(url,desired_language):
|
|
120 |
transcript.is_generated,
|
121 |
transcript.is_translatable,
|
122 |
transcript_translation_languages.append(transcript.translation_languages),
|
123 |
-
|
124 |
print(lista)
|
125 |
n_size=int(len(lista)/4)
|
126 |
print("There are {} avialable scripts".format(n_size))
|
@@ -149,7 +148,7 @@ def get_transcript(url,desired_language):
|
|
149 |
# we try filter for manually created transcripts
|
150 |
print('We extract manually created transcripts')
|
151 |
transcript = transcript_list.find_manually_created_transcript([language_code])
|
152 |
-
|
153 |
elif is_automatic:
|
154 |
print('We extract generated transcript')
|
155 |
# or automatically generated ones, but not translated
|
@@ -169,7 +168,7 @@ def get_transcript(url,desired_language):
|
|
169 |
transcript_translated=transcript_translated.fetch()
|
170 |
translated=clean_transcript(transcript_translated)
|
171 |
is_translated = True
|
172 |
-
script_translated = ""
|
173 |
if is_translated :
|
174 |
script_translated = translated
|
175 |
|
@@ -307,7 +306,7 @@ def video_to_translate(url,initial_language,final_language):
|
|
307 |
new_audioclip = CompositeAudioClip([audioclip])
|
308 |
videoclip.audio = new_audioclip
|
309 |
new_video="video_translated_"+lang+".mp4"
|
310 |
-
|
311 |
# Return back to main directory
|
312 |
os.chdir(home_dir)
|
313 |
print('Final directory',os.getcwd())
|
@@ -327,7 +326,7 @@ gr.Interface(
|
|
327 |
fn=video_to_translate,
|
328 |
inputs=[url, initial_language, final_language],
|
329 |
outputs='video',
|
330 |
-
verbose=True,
|
331 |
title='Video Youtube Translator',
|
332 |
description='A simple application that translates Youtube small videos from English, Italian, Japanese, Russian, Spanish, and German to Italian, Spanish, Russian, English, and Japanese. Wait one minute to process.',
|
333 |
article='''<div>
|
|
|
5 |
|
6 |
# importing all necessary libraries
|
7 |
import httpcore
|
|
|
8 |
import pathlib
|
9 |
import sys, os
|
10 |
from gtts import gTTS
|
|
|
38 |
return True
|
39 |
#This will return the length of the video in sec as an int
|
40 |
video_length = yt.length
|
41 |
+
if video_length > 600:
|
42 |
print("Your video is larger than 10 minutes")
|
43 |
return True
|
44 |
else:
|
|
|
71 |
# Calling the unlink method on the path
|
72 |
file.unlink()
|
73 |
except Exception:
|
74 |
+
print("I cannot delete the file because it is being used by another process")
|
75 |
|
76 |
def getSize(filename):
|
77 |
st = os.stat(filename)
|
|
|
93 |
(t != '[música]') and \
|
94 |
(t != '[Música]') and \
|
95 |
(t != '[音楽]') and \
|
96 |
+
(t != '[音乐]')
|
97 |
) :
|
98 |
script += t + " "
|
99 |
return script
|
|
|
119 |
transcript.is_generated,
|
120 |
transcript.is_translatable,
|
121 |
transcript_translation_languages.append(transcript.translation_languages),
|
122 |
+
])
|
123 |
print(lista)
|
124 |
n_size=int(len(lista)/4)
|
125 |
print("There are {} avialable scripts".format(n_size))
|
|
|
148 |
# we try filter for manually created transcripts
|
149 |
print('We extract manually created transcripts')
|
150 |
transcript = transcript_list.find_manually_created_transcript([language_code])
|
151 |
+
|
152 |
elif is_automatic:
|
153 |
print('We extract generated transcript')
|
154 |
# or automatically generated ones, but not translated
|
|
|
168 |
transcript_translated=transcript_translated.fetch()
|
169 |
translated=clean_transcript(transcript_translated)
|
170 |
is_translated = True
|
171 |
+
script_translated = ""
|
172 |
if is_translated :
|
173 |
script_translated = translated
|
174 |
|
|
|
306 |
new_audioclip = CompositeAudioClip([audioclip])
|
307 |
videoclip.audio = new_audioclip
|
308 |
new_video="video_translated_"+lang+".mp4"
|
309 |
+
|
310 |
# Return back to main directory
|
311 |
os.chdir(home_dir)
|
312 |
print('Final directory',os.getcwd())
|
|
|
326 |
fn=video_to_translate,
|
327 |
inputs=[url, initial_language, final_language],
|
328 |
outputs='video',
|
329 |
+
#verbose=True, # This parameter has been removed from gr.Interface
|
330 |
title='Video Youtube Translator',
|
331 |
description='A simple application that translates Youtube small videos from English, Italian, Japanese, Russian, Spanish, and German to Italian, Spanish, Russian, English, and Japanese. Wait one minute to process.',
|
332 |
article='''<div>
|