Spaces:
Runtime error
Runtime error
cleanup
Browse files
app.py
CHANGED
@@ -4,29 +4,17 @@ from transformers import pipeline
|
|
4 |
from pytube import YouTube
|
5 |
from datasets import Dataset, Audio
|
6 |
from moviepy.editor import AudioFileClip
|
7 |
-
|
8 |
-
# import googletrans # googletrans api
|
9 |
-
# from googletrans import Translator # googletrans api
|
10 |
-
# from google_trans_new import google_translator # google_trans_new api
|
11 |
-
from deep_translator import GoogleTranslator # MicrosoftTranslator
|
12 |
|
13 |
pipe = pipeline(model="Neprox/model")
|
14 |
-
|
15 |
-
# translator = Translator() # googletrans api
|
16 |
-
|
17 |
-
# Get languages available for translation
|
18 |
-
#languages = []
|
19 |
-
#for code, name in googletrans.LANGUAGES.items():
|
20 |
-
# language = f"{name.capitalize()} ({code})"
|
21 |
-
# languages.append(language)
|
22 |
languages = [
|
23 |
-
"French (fr)",
|
24 |
"English (en)",
|
25 |
"German (de)",
|
|
|
26 |
"Spanish (es)",
|
27 |
]
|
28 |
|
29 |
-
|
30 |
def download_from_youtube(url):
|
31 |
"""
|
32 |
Downloads the video from the given YouTube URL and returns the path to the audio file.
|
@@ -91,10 +79,6 @@ def get_translation(text, target_lang="English (en)"):
|
|
91 |
"""
|
92 |
lang_code = target_lang.split(" ")[-1][1:-1]
|
93 |
return GoogleTranslator(source='sv', target=lang_code).translate(text)
|
94 |
-
# return translator.translate(text, lang_tgt=lang_code) # googletrans_new api
|
95 |
-
# result = translator.translate(text, lang_code, 'sv') # googletrans api
|
96 |
-
# return result.text # googletrans api
|
97 |
-
|
98 |
|
99 |
def translate(audio, url, seconds_max, target_lang):
|
100 |
"""
|
@@ -115,7 +99,7 @@ def translate(audio, url, seconds_max, target_lang):
|
|
115 |
for i, (seconds, output) in enumerate(zip(segment_start_times, pred)):
|
116 |
text += f"[Segment {i+1}/{n_segments}, start time {get_timestamp(seconds)}]\n"
|
117 |
text += f"{output['text']}\n"
|
118 |
-
text += f"[Translation
|
119 |
text += f"{get_translation(output['text'], target_lang)}\n\n"
|
120 |
return text
|
121 |
|
@@ -129,11 +113,11 @@ iface = gr.Interface(
|
|
129 |
gr.Audio(source="microphone", type="filepath", label="Translate from Microphone"),
|
130 |
gr.Text(max_lines=1, placeholder="Enter YouTube Link with Swedish speech to be translated", label="Translate from YouTube URL"),
|
131 |
gr.Slider(minimum=30, maximum=300, value=30, step=30, label="Number of seconds to translate from YouTube URL"),
|
132 |
-
gr.Dropdown(languages, label="Target language")
|
133 |
],
|
134 |
outputs="text",
|
135 |
title="Whisper Small Swedish",
|
136 |
-
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
137 |
)
|
138 |
|
139 |
iface.launch()
|
|
|
4 |
from pytube import YouTube
|
5 |
from datasets import Dataset, Audio
|
6 |
from moviepy.editor import AudioFileClip
|
7 |
+
from deep_translator import GoogleTranslator
|
|
|
|
|
|
|
|
|
8 |
|
9 |
pipe = pipeline(model="Neprox/model")
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
languages = [
|
|
|
12 |
"English (en)",
|
13 |
"German (de)",
|
14 |
+
"French (fr)",
|
15 |
"Spanish (es)",
|
16 |
]
|
17 |
|
|
|
18 |
def download_from_youtube(url):
|
19 |
"""
|
20 |
Downloads the video from the given YouTube URL and returns the path to the audio file.
|
|
|
79 |
"""
|
80 |
lang_code = target_lang.split(" ")[-1][1:-1]
|
81 |
return GoogleTranslator(source='sv', target=lang_code).translate(text)
|
|
|
|
|
|
|
|
|
82 |
|
83 |
def translate(audio, url, seconds_max, target_lang):
|
84 |
"""
|
|
|
99 |
for i, (seconds, output) in enumerate(zip(segment_start_times, pred)):
|
100 |
text += f"[Segment {i+1}/{n_segments}, start time {get_timestamp(seconds)}]\n"
|
101 |
text += f"{output['text']}\n"
|
102 |
+
text += f"[Translation to {target_lang}]\n"
|
103 |
text += f"{get_translation(output['text'], target_lang)}\n\n"
|
104 |
return text
|
105 |
|
|
|
113 |
gr.Audio(source="microphone", type="filepath", label="Translate from Microphone"),
|
114 |
gr.Text(max_lines=1, placeholder="Enter YouTube Link with Swedish speech to be translated", label="Translate from YouTube URL"),
|
115 |
gr.Slider(minimum=30, maximum=300, value=30, step=30, label="Number of seconds to translate from YouTube URL"),
|
116 |
+
gr.Dropdown(languages, value="English (en)", label="Target language")
|
117 |
],
|
118 |
outputs="text",
|
119 |
title="Whisper Small Swedish",
|
120 |
+
description="Realtime demo for Swedish speech recognition with translation using a fine-tuned Whisper small model.",
|
121 |
)
|
122 |
|
123 |
iface.launch()
|