Commit
·
2c9e1d7
1
Parent(s):
94185cd
Update app.py
Browse files
app.py
CHANGED
@@ -259,7 +259,7 @@ def video_translation(video_path, target_language, speaker_model, hf_token, deep
|
|
259 |
|
260 |
return video_with_dubbing
|
261 |
|
262 |
-
def translate_video(
|
263 |
try:
|
264 |
if not video_path and not youtube_link:
|
265 |
gr.Warning("You should either upload video or input a YouTube link")
|
@@ -269,24 +269,43 @@ def translate_video(_, video_path, __, youtube_link, ___, target_language, speak
|
|
269 |
dubbed_video = video_translation(video_path, target_language, speaker_model, HF_TOKEN, DEEPL_TOKEN)
|
270 |
except Exception as e:
|
271 |
print(f"An error occurred: {e}")
|
|
|
272 |
return gr.components.Video(dubbed_video)
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
gr.Markdown("
|
279 |
-
gr.
|
280 |
-
|
281 |
-
gr.
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
gr.
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
return video_with_dubbing
|
261 |
|
262 |
+
def translate_video(video_path, youtube_link, target_language, speaker_model):
|
263 |
try:
|
264 |
if not video_path and not youtube_link:
|
265 |
gr.Warning("You should either upload video or input a YouTube link")
|
|
|
269 |
dubbed_video = video_translation(video_path, target_language, speaker_model, HF_TOKEN, DEEPL_TOKEN)
|
270 |
except Exception as e:
|
271 |
print(f"An error occurred: {e}")
|
272 |
+
raise e
|
273 |
return gr.components.Video(dubbed_video)
|
274 |
|
275 |
+
def clear_inputs():
|
276 |
+
return None, "", None, None
|
277 |
+
|
278 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
279 |
+
gr.Markdown("<h1 style='text-align: center;'>🌐AI Video Translation</h2>")
|
280 |
+
gr.Markdown("<h3 style='text-align: center;'>Currently supported languages are: English, Polish, Ukrainian, and Russian</h3>")
|
281 |
+
|
282 |
+
with gr.Row():
|
283 |
+
with gr.Column():
|
284 |
+
gr.Markdown("<h2 style='text-align: center;'>Inputs</h3>")
|
285 |
+
video = gr.Video(label="Upload a video file")
|
286 |
+
gr.Markdown("<h3 style='text-align: center;'>OR</h3>")
|
287 |
+
youtube_link = gr.Textbox(label="Paste YouTube link")
|
288 |
+
gr.Markdown("---")
|
289 |
+
target_language = gr.Dropdown(["en", "pl", "uk", "ru"], value="pl", label="Select translation target language")
|
290 |
+
speaker_model = gr.Dropdown(["(Recommended) XTTS_V2", "VITs (will be default for Ukrainian)"], value="(Recommended) XTTS_V2", label="Select text-to-speech generation model")
|
291 |
+
with gr.Row():
|
292 |
+
clear_btn = gr.Button("Clear inputs")
|
293 |
+
translate_btn = gr.Button("Translate")
|
294 |
+
|
295 |
+
with gr.Column():
|
296 |
+
gr.Markdown("<h2 style='text-align: center;'>Translated Video</h3>")
|
297 |
+
output_video = gr.Video(label="Translated video")
|
298 |
+
|
299 |
+
translate_btn.click(
|
300 |
+
fn=translate_video,
|
301 |
+
inputs=[video, youtube_link, target_language, speaker_model],
|
302 |
+
outputs=output_video
|
303 |
+
)
|
304 |
+
|
305 |
+
clear_btn.click(
|
306 |
+
fn=clear_inputs,
|
307 |
+
inputs=[],
|
308 |
+
outputs=[video, youtube_link, target_language, speaker_model]
|
309 |
+
)
|
310 |
+
|
311 |
+
demo.launch(show_error=True, debug=True, share=True)
|