Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
|
|
1 |
from gtts import gTTS
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
import speech_recognition as sr
|
5 |
from googletrans import Translator, constants
|
6 |
from pprint import pprint
|
|
|
|
|
7 |
from moviepy.editor import *
|
8 |
-
|
9 |
-
#Downloading the Demo video
|
10 |
-
os.system('wget https://huggingface.co/spaces/ruslanmv/Video-Translator/resolve/main/obama.mp4')
|
11 |
-
os.system('ls')
|
12 |
def video_to_translate(file_obj,initial_language,final_language):
|
13 |
# Insert Local Video File Path
|
14 |
videoclip = VideoFileClip(file_obj.name)
|
@@ -30,8 +29,6 @@ def video_to_translate(file_obj,initial_language,final_language):
|
|
30 |
elif initial_language == "Japanese":
|
31 |
lang_in='ja-JP'
|
32 |
|
33 |
-
|
34 |
-
|
35 |
# open the file
|
36 |
with sr.AudioFile("test.wav") as source:
|
37 |
# listen for the data (load audio to memory)
|
@@ -49,18 +46,18 @@ def video_to_translate(file_obj,initial_language,final_language):
|
|
49 |
lang='ru'
|
50 |
elif final_language == "German":
|
51 |
lang='de'
|
52 |
-
|
|
|
|
|
|
|
53 |
print(lang)
|
54 |
# init the Google API translator
|
55 |
translator = Translator()
|
56 |
translation = translator.translate(text, dest=lang)
|
57 |
#translation.text
|
58 |
trans=translation.text
|
59 |
-
|
60 |
-
|
61 |
myobj = gTTS(text=trans, lang=lang, slow=False)
|
62 |
myobj.save("audio.wav")
|
63 |
-
|
64 |
# loading audio file
|
65 |
audioclip = AudioFileClip("audio.wav")
|
66 |
|
@@ -72,7 +69,7 @@ def video_to_translate(file_obj,initial_language,final_language):
|
|
72 |
return 'new_filename.mp4'
|
73 |
|
74 |
initial_language = gr.inputs.Dropdown(["English","Italian","Japanese","Russian","Spanish","German"])
|
75 |
-
final_language = gr.inputs.Dropdown([ "Russian","Italian","Spanish","German","English"])
|
76 |
|
77 |
|
78 |
gr.Interface(fn = video_to_translate,
|
@@ -87,5 +84,10 @@ gr.Interface(fn = video_to_translate,
|
|
87 |
For more information visit <a href="https://ruslanmv.com/">ruslanmv.com</a>
|
88 |
</p>
|
89 |
</div>''',
|
90 |
-
examples=[['obama.mp4',"English",'Spanish']
|
|
|
|
|
|
|
|
|
|
|
91 |
).launch()
|
|
|
1 |
+
# coding=utf8
|
2 |
from gtts import gTTS
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
import speech_recognition as sr
|
6 |
from googletrans import Translator, constants
|
7 |
from pprint import pprint
|
8 |
+
#pip install moviepy
|
9 |
+
#pip3 install googletrans
|
10 |
from moviepy.editor import *
|
|
|
|
|
|
|
|
|
11 |
def video_to_translate(file_obj,initial_language,final_language):
|
12 |
# Insert Local Video File Path
|
13 |
videoclip = VideoFileClip(file_obj.name)
|
|
|
29 |
elif initial_language == "Japanese":
|
30 |
lang_in='ja-JP'
|
31 |
|
|
|
|
|
32 |
# open the file
|
33 |
with sr.AudioFile("test.wav") as source:
|
34 |
# listen for the data (load audio to memory)
|
|
|
46 |
lang='ru'
|
47 |
elif final_language == "German":
|
48 |
lang='de'
|
49 |
+
elif final_language == "Japanese":
|
50 |
+
lang='ja'
|
51 |
+
elif final_language == "Chinese":
|
52 |
+
lang='zh-CN'
|
53 |
print(lang)
|
54 |
# init the Google API translator
|
55 |
translator = Translator()
|
56 |
translation = translator.translate(text, dest=lang)
|
57 |
#translation.text
|
58 |
trans=translation.text
|
|
|
|
|
59 |
myobj = gTTS(text=trans, lang=lang, slow=False)
|
60 |
myobj.save("audio.wav")
|
|
|
61 |
# loading audio file
|
62 |
audioclip = AudioFileClip("audio.wav")
|
63 |
|
|
|
69 |
return 'new_filename.mp4'
|
70 |
|
71 |
initial_language = gr.inputs.Dropdown(["English","Italian","Japanese","Russian","Spanish","German"])
|
72 |
+
final_language = gr.inputs.Dropdown([ "Russian","Italian","Spanish","German","English","Japanese","Chinese"])
|
73 |
|
74 |
|
75 |
gr.Interface(fn = video_to_translate,
|
|
|
84 |
For more information visit <a href="https://ruslanmv.com/">ruslanmv.com</a>
|
85 |
</p>
|
86 |
</div>''',
|
87 |
+
examples=[['obama.mp4',"English",'Spanish'],
|
88 |
+
['obama.mp4',"English",'Italian'],
|
89 |
+
['obama.mp4',"English",'German'],
|
90 |
+
['obama.mp4',"English",'Japanese'],
|
91 |
+
['obama.mp4',"English",'Chinese']
|
92 |
+
]
|
93 |
).launch()
|