Dani commited on
Commit
e2f3c1e
1 Parent(s): 6d34151
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -11,6 +11,7 @@ import os
11
  #
12
  # login(token=token, add_to_git_credential=True)
13
  pipe = pipeline(model="dacavi/whisper-small-es")
 
14
  def translate_text(text, target_language_code):
15
  translate = boto3.client('translate')
16
 
@@ -23,30 +24,35 @@ def translate_text(text, target_language_code):
23
  translated_text = response['TranslatedText']
24
  return translated_text
25
 
26
- def translate_video(video_url):
27
- # Download video and extract audio
28
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio:
29
- # os.system(f"yt-dlp -o {temp_audio.name} -x --audio-format wav {video_url}")
30
- os.system(f"yt-dlp -o audioSample.wav -x --audio-format wav {video_url}")
 
31
 
32
- print("Downloaded audio:", temp_audio.name)
33
 
34
 
35
- # Transcribe audio
36
- text = pipe("audioSample.wav")["text"]
37
- translatedText = translate_text(text,"en")
38
 
39
- # Clean up temporary files
40
- os.remove("audioSample.wav")
 
 
41
  return translatedText
42
 
43
  iface = gr.Interface(
44
  fn=translate_video,
45
- inputs="text",
 
 
46
  outputs="text",
47
  live=True,
48
- title="Spanish to English video translation",
49
- description="Paste the URL of a Spanish video to translate the text to English spoken content.",
50
  )
51
 
52
  iface.launch()
 
11
  #
12
  # login(token=token, add_to_git_credential=True)
13
  pipe = pipeline(model="dacavi/whisper-small-es")
14
+ language_codes = ["en", "fr", "de", "it"]
15
  def translate_text(text, target_language_code):
16
  translate = boto3.client('translate')
17
 
 
24
  translated_text = response['TranslatedText']
25
  return translated_text
26
 
27
+ def translate_video(video_url,language):
28
+ if video_url and language:
29
+ # Download video and extract audio
30
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio:
31
+ # os.system(f"yt-dlp -o {temp_audio.name} -x --audio-format wav {video_url}")
32
+ os.system(f"yt-dlp -o audioSample.wav -x --audio-format wav {video_url}")
33
 
34
+ print("Downloaded audio:", temp_audio.name)
35
 
36
 
37
+ # Transcribe audio
38
+ text = pipe("audioSample.wav")["text"]
39
+ translatedText = translate_text(text,language)
40
 
41
+ # Clean up temporary files
42
+ os.remove("audioSample.wav")
43
+ else:
44
+ translatedText = "Please fill in both parameters."
45
  return translatedText
46
 
47
  iface = gr.Interface(
48
  fn=translate_video,
49
+ inputs=[gr.Textbox(label="Video URL"),
50
+ gr.Dropdown(choices=language_codes, label="Select Target Language")
51
+ ],
52
  outputs="text",
53
  live=True,
54
+ title="SPANISH VIDEO TRANSLATION",
55
+ description="Paste the URL of a Spanish video to translate the text to any of the available languages.",
56
  )
57
 
58
  iface.launch()