vitaliy-sharandin commited on
Commit
2c9e1d7
·
1 Parent(s): 94185cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
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(_, 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,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
- inputs = [
276
- gr.Markdown("## Currently supported languages are: English, Polish, Ukrainian and Russian"),
277
- gr.Video(label="Upload a video file"),
278
- gr.Markdown("**OR**"),
279
- gr.Textbox(label="Paste YouTube link"),
280
- gr.Markdown("---"),
281
- gr.Dropdown(["en", "pl", "uk", "ru"], value="pl", label="Select translation target language"),
282
- gr.Dropdown(["(Recommended) XTTS_V2", "VITs (will be default for Ukrainian)"], value="(Recommended) XTTS_V2", label="Select text-to-speech generation model")
283
- ]
284
-
285
- outputs = gr.Video(label="Translated video")
286
-
287
- gr.Interface(fn=translate_video,
288
- inputs=inputs,
289
- outputs=outputs,
290
- title="🌐AI Video Translation",
291
- theme=gr.themes.Base()
292
- ).launch(show_error=True, debug=True, share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)