Ruslan Magana Vsevolodovna
commited on
Commit
·
590d379
1
Parent(s):
a403fe8
Small fixes
Browse files- .gitignore +4 -0
- app.py +42 -11
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
*.mp4
|
| 3 |
+
*.pyc
|
| 4 |
+
*.wav
|
app.py
CHANGED
|
@@ -28,10 +28,26 @@ def download_video(url):
|
|
| 28 |
print("Downloaded")
|
| 29 |
return local_file
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def validate_url(url):
|
| 32 |
import validators
|
| 33 |
if not validators.url(url):
|
| 34 |
print("Hi there URL seems invalid ")
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def cleanup():
|
|
@@ -69,6 +85,14 @@ def generate_transcript(url,lang_api):
|
|
| 69 |
return script
|
| 70 |
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def video_to_translate(url,initial_language,final_language):
|
| 73 |
|
| 74 |
#Internal definitions
|
|
@@ -102,16 +126,14 @@ def video_to_translate(url,initial_language,final_language):
|
|
| 102 |
lang='de'
|
| 103 |
elif final_language == "Japanese":
|
| 104 |
lang='ja'
|
| 105 |
-
|
| 106 |
# Initial directory
|
| 107 |
-
home_dir
|
|
|
|
|
|
|
| 108 |
print('Initial directory:',home_dir)
|
| 109 |
cleanup()
|
| 110 |
# Temporal directory
|
| 111 |
-
temp_dir=os.path.join(home_dir, "temp")
|
| 112 |
print('Temporal directory:',temp_dir)
|
| 113 |
-
#Create temp directory
|
| 114 |
-
pathlib.Path(temp_dir).mkdir(parents=True, exist_ok=True)
|
| 115 |
# Go to temp directory
|
| 116 |
os.chdir(temp_dir)
|
| 117 |
print('Changing temporal directory',os.getcwd())
|
|
@@ -159,7 +181,15 @@ def video_to_translate(url,initial_language,final_language):
|
|
| 159 |
print(type(text))
|
| 160 |
|
| 161 |
else:
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
#print(text)
|
| 164 |
print("Destination language ",lang)
|
| 165 |
|
|
@@ -210,11 +240,11 @@ gr.Interface(fn = video_to_translate,
|
|
| 210 |
outputs = 'video',
|
| 211 |
verbose = True,
|
| 212 |
title = 'Video Youtube Translator',
|
| 213 |
-
description = 'A simple application that translates Youtube videos from English, Italian, Japanese, Russian, Spanish, and German to Italian, Spanish, Russian, English and Japanese. Wait one minute to process.',
|
| 214 |
article =
|
| 215 |
'''<div>
|
| 216 |
-
<p style="text-align: center"> All you need to do is to paste the Youtube link
|
| 217 |
-
For more information visit <a href="https://ruslanmv.com/">ruslanmv.com</a>
|
| 218 |
</p>
|
| 219 |
</div>''',
|
| 220 |
|
|
@@ -222,8 +252,9 @@ gr.Interface(fn = video_to_translate,
|
|
| 222 |
["https://www.youtube.com/watch?v=Cu3R5it4cQs&list", "English","Italian"],
|
| 223 |
["https://www.youtube.com/watch?v=fkGCLIQx1MI", "English","Spanish"],
|
| 224 |
["https://www.youtube.com/watch?v=fkGCLIQx1MI", "English","Russian"],
|
| 225 |
-
["https://www.youtube.com/watch?v=
|
| 226 |
["https://www.youtube.com/watch?v=qzzweIQoIOU", "Japanese","English"],
|
| 227 |
-
["https://www.youtube.com/watch?v=
|
|
|
|
| 228 |
]
|
| 229 |
).launch()
|
|
|
|
| 28 |
print("Downloaded")
|
| 29 |
return local_file
|
| 30 |
|
| 31 |
+
def validate_youtube(url):
|
| 32 |
+
#This creates a youtube objet
|
| 33 |
+
yt = YouTube(url)
|
| 34 |
+
#This will return the length of the video in sec as an int
|
| 35 |
+
video_length = yt.length
|
| 36 |
+
if video_length > 600:
|
| 37 |
+
print("Your video is larger than 10 minutes")
|
| 38 |
+
#return False
|
| 39 |
+
else:
|
| 40 |
+
print("Your video is less than 10 minutes")
|
| 41 |
+
#return True
|
| 42 |
+
|
| 43 |
+
|
| 44 |
def validate_url(url):
|
| 45 |
import validators
|
| 46 |
if not validators.url(url):
|
| 47 |
print("Hi there URL seems invalid ")
|
| 48 |
+
return False
|
| 49 |
+
else:
|
| 50 |
+
return True
|
| 51 |
|
| 52 |
|
| 53 |
def cleanup():
|
|
|
|
| 85 |
return script
|
| 86 |
|
| 87 |
|
| 88 |
+
# Set environment variables
|
| 89 |
+
home_dir = os.getcwd()
|
| 90 |
+
temp_dir=os.path.join(home_dir, "temp")
|
| 91 |
+
#Create temp directory
|
| 92 |
+
pathlib.Path(temp_dir).mkdir(parents=True, exist_ok=True)
|
| 93 |
+
os.environ['home_dir'] = home_dir
|
| 94 |
+
os.environ['temp_dir'] = temp_dir
|
| 95 |
+
|
| 96 |
def video_to_translate(url,initial_language,final_language):
|
| 97 |
|
| 98 |
#Internal definitions
|
|
|
|
| 126 |
lang='de'
|
| 127 |
elif final_language == "Japanese":
|
| 128 |
lang='ja'
|
|
|
|
| 129 |
# Initial directory
|
| 130 |
+
home_dir= os.getenv('home_dir')
|
| 131 |
+
temp_dir = os.getenv('temp_dir')
|
| 132 |
+
os.chdir(home_dir)
|
| 133 |
print('Initial directory:',home_dir)
|
| 134 |
cleanup()
|
| 135 |
# Temporal directory
|
|
|
|
| 136 |
print('Temporal directory:',temp_dir)
|
|
|
|
|
|
|
| 137 |
# Go to temp directory
|
| 138 |
os.chdir(temp_dir)
|
| 139 |
print('Changing temporal directory',os.getcwd())
|
|
|
|
| 181 |
print(type(text))
|
| 182 |
|
| 183 |
else:
|
| 184 |
+
try:
|
| 185 |
+
text = r.recognize_google(audio_data, language = lang_in)
|
| 186 |
+
except Exception:
|
| 187 |
+
print("This video cannot be recognized")
|
| 188 |
+
cleanup()
|
| 189 |
+
# Return back to main directory
|
| 190 |
+
os.chdir(home_dir)
|
| 191 |
+
return "./demo/tryagain.mp4"
|
| 192 |
+
|
| 193 |
#print(text)
|
| 194 |
print("Destination language ",lang)
|
| 195 |
|
|
|
|
| 240 |
outputs = 'video',
|
| 241 |
verbose = True,
|
| 242 |
title = 'Video Youtube Translator',
|
| 243 |
+
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.',
|
| 244 |
article =
|
| 245 |
'''<div>
|
| 246 |
+
<p style="text-align: center"> All you need to do is to paste the Youtube link and hit submit,, then wait for compiling. After that click on Play/Pause for listing to the video. The video is saved in an mp4 format.
|
| 247 |
+
The lenght video limit is 10 minutes. For more information visit <a href="https://ruslanmv.com/">ruslanmv.com</a>
|
| 248 |
</p>
|
| 249 |
</div>''',
|
| 250 |
|
|
|
|
| 252 |
["https://www.youtube.com/watch?v=Cu3R5it4cQs&list", "English","Italian"],
|
| 253 |
["https://www.youtube.com/watch?v=fkGCLIQx1MI", "English","Spanish"],
|
| 254 |
["https://www.youtube.com/watch?v=fkGCLIQx1MI", "English","Russian"],
|
| 255 |
+
["https://www.youtube.com/watch?v=QbkhvLrlex4", "Russian","English"],
|
| 256 |
["https://www.youtube.com/watch?v=qzzweIQoIOU", "Japanese","English"],
|
| 257 |
+
["https://www.youtube.com/watch?v=nOGZvu6tJFE", "German","Spanish"]
|
| 258 |
+
|
| 259 |
]
|
| 260 |
).launch()
|