Spaces:
Paused
Paused
Commit
·
92bc38d
1
Parent(s):
0bd56e6
Add language selection
Browse files
app.py
CHANGED
@@ -7,17 +7,19 @@ from share_btn import community_icon_html, loading_icon_html, share_js
|
|
7 |
|
8 |
model = whisper.load_model("medium")
|
9 |
|
|
|
|
|
10 |
|
11 |
|
12 |
-
def inference(audio):
|
13 |
audio = whisper.load_audio(audio)
|
14 |
audio = whisper.pad_or_trim(audio)
|
15 |
|
16 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
17 |
|
18 |
-
_, probs = model.detect_language(mel)
|
19 |
|
20 |
-
options = whisper.DecodingOptions(fp16 = False)
|
21 |
result = whisper.decode(model, mel, options)
|
22 |
|
23 |
print(result.text)
|
@@ -146,7 +148,11 @@ with block:
|
|
146 |
type="filepath"
|
147 |
)
|
148 |
|
149 |
-
|
|
|
|
|
|
|
|
|
150 |
text = gr.Textbox(show_label=False, elem_id="result-textarea")
|
151 |
with gr.Group(elem_id="share-btn-container"):
|
152 |
community_icon = gr.HTML(community_icon_html, visible=False)
|
@@ -156,7 +162,7 @@ with block:
|
|
156 |
|
157 |
|
158 |
|
159 |
-
btn.click(inference, inputs=[audio], outputs=[text, community_icon, loading_icon, share_button])
|
160 |
share_button.click(None, [], [], _js=share_js)
|
161 |
|
162 |
gr.HTML('''
|
|
|
7 |
|
8 |
model = whisper.load_model("medium")
|
9 |
|
10 |
+
languages = {long_name: short_name for short_name, long_name in whisper.tokenizer.LANGUAGES.items()}
|
11 |
+
|
12 |
|
13 |
|
14 |
+
def inference(audio, language):
|
15 |
audio = whisper.load_audio(audio)
|
16 |
audio = whisper.pad_or_trim(audio)
|
17 |
|
18 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
19 |
|
20 |
+
#_, probs = model.detect_language(mel)
|
21 |
|
22 |
+
options = whisper.DecodingOptions(fp16 = False, language=language)
|
23 |
result = whisper.decode(model, mel, options)
|
24 |
|
25 |
print(result.text)
|
|
|
148 |
type="filepath"
|
149 |
)
|
150 |
|
151 |
+
language_long_name = gr.Dropdown(
|
152 |
+
list(languages.keys()), value="auto", multiselect=False, label="Taal", info="Taal van de gesproken tekst. Auto voor automatische detectie."
|
153 |
+
)
|
154 |
+
|
155 |
+
btn = gr.Button("Transcribeer")
|
156 |
text = gr.Textbox(show_label=False, elem_id="result-textarea")
|
157 |
with gr.Group(elem_id="share-btn-container"):
|
158 |
community_icon = gr.HTML(community_icon_html, visible=False)
|
|
|
162 |
|
163 |
|
164 |
|
165 |
+
btn.click(inference, inputs=[audio, languages[language_long_name]], outputs=[text, community_icon, loading_icon, share_button])
|
166 |
share_button.click(None, [], [], _js=share_js)
|
167 |
|
168 |
gr.HTML('''
|