Maximofn commited on
Commit
d728ac6
1 Parent(s): cfd5440

Pre translate audio. Code is writen but fails, so that i commented it

Browse files
Files changed (1) hide show
  1. translatube.py +16 -2
translatube.py CHANGED
@@ -5,10 +5,16 @@ from pytube import YouTube
5
  import re
6
  import subprocess
7
  from lang_list import ORIGINAL_LANGUAGE_NAME_TO_CODE, S2ST_TARGET_ORIGINAL_LANGUAGE_NAMES
 
 
 
8
 
9
  YOUTUBE = "youtube"
10
  TWITCH = "twitch"
11
 
 
 
 
12
  def copy_url_from_clipboard():
13
  return pyperclip.paste()
14
 
@@ -30,7 +36,7 @@ def get_youtube_video_id(url):
30
 
31
  def is_valid_url(url):
32
  button = gr.Button(size="sm", value="translate", min_width="10px", scale=0, visible=True)
33
- original_audio = gr.Audio(label="Original audio", elem_id="original_audio", visible=True)
34
  translated_audio = gr.Audio(label="Translated audio", elem_id="translated_audio", visible=True)
35
  source_languaje = gr.Dropdown(visible=True, label="Source languaje", show_label=True, value="English", choices=ORIGINAL_LANGUAGE_NAME_TO_CODE, scale=1, interactive=True)
36
  target_languaje = gr.Dropdown(visible=True, label="Target languaje", show_label=True, value="Español", choices=S2ST_TARGET_ORIGINAL_LANGUAGE_NAMES, scale=1, interactive=True)
@@ -48,7 +54,7 @@ def is_valid_url(url):
48
  )
49
  elif "twitch" in url.lower() or "twitch.tv" in url.lower():
50
  return (
51
- gr.Image(value="assets/twitch.webp", visible=True),
52
  source_languaje,
53
  target_languaje,
54
  button,
@@ -84,6 +90,13 @@ def get_audio_from_video(url, stream_page):
84
 
85
  return gr.Audio("audio.mkv", label="Original audio", elem_id="original_audio", visible=True)
86
 
 
 
 
 
 
 
 
87
 
88
  with gr.Blocks() as demo:
89
  with gr.Row(variant="panel"):
@@ -107,5 +120,6 @@ with gr.Blocks() as demo:
107
  translated_audio = gr.Audio(label="Translated audio", elem_id="translated_audio", visible=visible)
108
  url_textbox.change(fn=is_valid_url, inputs=url_textbox, outputs=[image, source_languaje, target_languaje, translate_button, stream_page, original_audio, translated_audio])
109
  translate_button.click(fn=get_audio_from_video, inputs=[url_textbox, stream_page], outputs=original_audio)
 
110
 
111
  demo.launch()
 
5
  import re
6
  import subprocess
7
  from lang_list import ORIGINAL_LANGUAGE_NAME_TO_CODE, S2ST_TARGET_ORIGINAL_LANGUAGE_NAMES
8
+ import torch
9
+ from seamless_communication.models.inference import Translator
10
+ import time
11
 
12
  YOUTUBE = "youtube"
13
  TWITCH = "twitch"
14
 
15
+ # Initialize a Translator object with a multitask model, vocoder on the GPU.
16
+ # translator = Translator("seamlessM4T_large", vocoder_name_or_card="vocoder_36langs", device=torch.device("cuda:0"))
17
+
18
  def copy_url_from_clipboard():
19
  return pyperclip.paste()
20
 
 
36
 
37
  def is_valid_url(url):
38
  button = gr.Button(size="sm", value="translate", min_width="10px", scale=0, visible=True)
39
+ original_audio = gr.Audio(label="Original audio", elem_id="original_audio", visible=True, interactive=False)
40
  translated_audio = gr.Audio(label="Translated audio", elem_id="translated_audio", visible=True)
41
  source_languaje = gr.Dropdown(visible=True, label="Source languaje", show_label=True, value="English", choices=ORIGINAL_LANGUAGE_NAME_TO_CODE, scale=1, interactive=True)
42
  target_languaje = gr.Dropdown(visible=True, label="Target languaje", show_label=True, value="Español", choices=S2ST_TARGET_ORIGINAL_LANGUAGE_NAMES, scale=1, interactive=True)
 
54
  )
55
  elif "twitch" in url.lower() or "twitch.tv" in url.lower():
56
  return (
57
+ gr.Image(value="assets/twitch.webp", visible=True, show_download_button=False, container=False),
58
  source_languaje,
59
  target_languaje,
60
  button,
 
90
 
91
  return gr.Audio("audio.mkv", label="Original audio", elem_id="original_audio", visible=True)
92
 
93
+ # def translate_audio(input_audio, target_languaje):
94
+ # print("Translating audio...")
95
+ # time.sleep(5)
96
+ # print("Translating audio...")
97
+ # _, wav, _ = translator.predict(input_audio, "s2st", target_languaje)
98
+ # return gr.Audio(wav, label="Translated audio", elem_id="translated_audio", visible=True)
99
+
100
 
101
  with gr.Blocks() as demo:
102
  with gr.Row(variant="panel"):
 
120
  translated_audio = gr.Audio(label="Translated audio", elem_id="translated_audio", visible=visible)
121
  url_textbox.change(fn=is_valid_url, inputs=url_textbox, outputs=[image, source_languaje, target_languaje, translate_button, stream_page, original_audio, translated_audio])
122
  translate_button.click(fn=get_audio_from_video, inputs=[url_textbox, stream_page], outputs=original_audio)
123
+ # original_audio.change(fn=translate_audio, inputs=[original_audio, target_languaje], outputs=translated_audio)
124
 
125
  demo.launch()