Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import subprocess
|
|
6 |
import gradio as gr
|
7 |
import translators as ts
|
8 |
from gradio_client import Client
|
|
|
9 |
from list_dict import translates, speakers
|
10 |
|
11 |
translate = translates
|
@@ -15,6 +16,7 @@ la = list(language.keys())[0]
|
|
15 |
speaker = speakers
|
16 |
sp = speaker[0]
|
17 |
|
|
|
18 |
file_name = 'audio'
|
19 |
main_video = 'video.mp4'
|
20 |
main_audio = f'{file_name}.wav'
|
@@ -60,12 +62,18 @@ def time_verify():
|
|
60 |
return j_time, r_time
|
61 |
|
62 |
def translator(text, TR_LANGUAGE, LANGUAGE):
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
64 |
return ts_text
|
65 |
|
66 |
def video_inputs(video, TR_LANGUAGE, LANGUAGE, SPEAKER):
|
67 |
gl = True
|
68 |
language = translate[TR_LANGUAGE]
|
|
|
69 |
|
70 |
if video is None:
|
71 |
raise gr.Error('No audio file submitted!')
|
@@ -81,13 +89,13 @@ def video_inputs(video, TR_LANGUAGE, LANGUAGE, SPEAKER):
|
|
81 |
if gl is True:
|
82 |
gl = False
|
83 |
raise gr.Error('Language has been reloaded, please select again!')
|
84 |
-
elif
|
85 |
raise gr.Error('Exceed maximum limit!')
|
86 |
|
87 |
try:
|
88 |
ff = ffmpy.FFmpeg(
|
89 |
inputs={
|
90 |
-
video:
|
91 |
},
|
92 |
outputs={
|
93 |
main_video: ['-y', '-map', '0:0', '-c:a', 'copy', '-f', 'mp4'],
|
@@ -120,8 +128,6 @@ def video_inputs(video, TR_LANGUAGE, LANGUAGE, SPEAKER):
|
|
120 |
raise gr.Error('Mismatched audio!')
|
121 |
except RemoteDisconnected as e:
|
122 |
raise gr.Error(f'API:{e}')
|
123 |
-
except ConnectionError as i:
|
124 |
-
raise gr.Error(f'translator ConnectionError:{i}')
|
125 |
|
126 |
async def amain():
|
127 |
communicate = edge_tts.Communicate(ts_text, SPEAKER)
|
|
|
6 |
import gradio as gr
|
7 |
import translators as ts
|
8 |
from gradio_client import Client
|
9 |
+
from http.client import RemoteDisconnected
|
10 |
from list_dict import translates, speakers
|
11 |
|
12 |
translate = translates
|
|
|
16 |
speaker = speakers
|
17 |
sp = speaker[0]
|
18 |
|
19 |
+
max_duration = 60
|
20 |
file_name = 'audio'
|
21 |
main_video = 'video.mp4'
|
22 |
main_audio = f'{file_name}.wav'
|
|
|
62 |
return j_time, r_time
|
63 |
|
64 |
def translator(text, TR_LANGUAGE, LANGUAGE):
|
65 |
+
try:
|
66 |
+
ts_text = ts.translate_text(text, translator=TR_LANGUAGE, from_language='auto', to_language=language[LANGUAGE])
|
67 |
+
except ConnectionError as i:
|
68 |
+
raise gr.Error(f'translator ConnectionError:{i}')
|
69 |
+
except ts.TranslatorError:
|
70 |
+
raise gr.Error('Translator error!')
|
71 |
return ts_text
|
72 |
|
73 |
def video_inputs(video, TR_LANGUAGE, LANGUAGE, SPEAKER):
|
74 |
gl = True
|
75 |
language = translate[TR_LANGUAGE]
|
76 |
+
get_time = float(gain_time(video))
|
77 |
|
78 |
if video is None:
|
79 |
raise gr.Error('No audio file submitted!')
|
|
|
89 |
if gl is True:
|
90 |
gl = False
|
91 |
raise gr.Error('Language has been reloaded, please select again!')
|
92 |
+
elif get_time > max_duration:
|
93 |
raise gr.Error('Exceed maximum limit!')
|
94 |
|
95 |
try:
|
96 |
ff = ffmpy.FFmpeg(
|
97 |
inputs={
|
98 |
+
video: f'-t {max_duration}'
|
99 |
},
|
100 |
outputs={
|
101 |
main_video: ['-y', '-map', '0:0', '-c:a', 'copy', '-f', 'mp4'],
|
|
|
128 |
raise gr.Error('Mismatched audio!')
|
129 |
except RemoteDisconnected as e:
|
130 |
raise gr.Error(f'API:{e}')
|
|
|
|
|
131 |
|
132 |
async def amain():
|
133 |
communicate = edge_tts.Communicate(ts_text, SPEAKER)
|