Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import os
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
# Zde byste inicializovali model Whisper s API klíčem, pokud je to potřeba
|
9 |
-
# U modelu Whisper od OpenAI to však obvykle není nutné
|
10 |
-
model = whisper.load_model("base")
|
11 |
|
12 |
def transcribe(audio_file):
|
13 |
"""
|
14 |
-
Transkribuje audio soubor pomocí modelu
|
15 |
"""
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
fn=transcribe,
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
|
|
3 |
|
4 |
+
# Nastavení modelu pro transkripci
|
5 |
+
model_name = "facebook/wav2vec2-base-960h"
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def transcribe(audio_file):
|
8 |
"""
|
9 |
+
Transkribuje audio soubor pomocí Wav2Vec2 modelu.
|
10 |
"""
|
11 |
+
# Načtení modelu a tokenizeru
|
12 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_name)
|
13 |
+
tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
|
14 |
+
|
15 |
+
# Převedení audio souboru na tokeny
|
16 |
+
input_values = tokenizer(audio_file, return_tensors="pt").input_values
|
17 |
+
|
18 |
+
# Transkripce audia
|
19 |
+
with gr.no_logging():
|
20 |
+
with gr.no_progress():
|
21 |
+
transcript = model(input_values).logits.argmax(dim=-1)
|
22 |
+
|
23 |
+
# Převedení výsledku na text
|
24 |
+
transcription = tokenizer.batch_decode(transcript)
|
25 |
+
|
26 |
+
return transcription[0]
|
27 |
|
28 |
iface = gr.Interface(
|
29 |
fn=transcribe,
|