fix transcribe bug
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app.py –
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
@@ -16,7 +16,7 @@ pipe = pipeline(
|
|
| 16 |
token=os.getenv("HF_TOKEN")
|
| 17 |
)
|
| 18 |
|
| 19 |
-
# Fix old Whisper checkpoints
|
| 20 |
if not hasattr(pipe.model.generation_config, "lang_to_id") or pipe.model.generation_config.lang_to_id is None:
|
| 21 |
pipe.model.generation_config.lang_to_id = {"is": 50259}
|
| 22 |
pipe.model.generation_config.task_to_id = {"transcribe": 50359, "translate": 50358}
|
|
@@ -24,21 +24,21 @@ if not hasattr(pipe.model.generation_config, "lang_to_id") or pipe.model.generat
|
|
| 24 |
|
| 25 |
print("Módel tilbúið!")
|
| 26 |
|
| 27 |
-
@spaces.GPU(duration=180)
|
| 28 |
def transcribe_single(audio_path):
|
| 29 |
if not audio_path:
|
| 30 |
return None, "Hladdu upp hljóðskrá", "00:00"
|
| 31 |
|
| 32 |
result = pipe(audio_path, chunk_length_s=30, batch_size=8)
|
| 33 |
text = result["text"].strip()
|
| 34 |
-
return audio_path, text, None #
|
| 35 |
|
| 36 |
with gr.Blocks(title="Íslenskt Whisper") as demo:
|
| 37 |
gr.Markdown("# Íslenskt Whisper – Mjög lágt WER")
|
| 38 |
gr.Markdown("Hladdu upp einni hljóðskrá (allt að 5 mín) → smelltu á Transcribe")
|
| 39 |
|
| 40 |
with gr.Row():
|
| 41 |
-
audio_in = gr.Audio(label="Hljóðskrá", type="filepath"
|
| 42 |
|
| 43 |
btn = gr.Button("Transcribe", variant="primary", size="lg")
|
| 44 |
|
|
@@ -47,7 +47,6 @@ with gr.Blocks(title="Íslenskt Whisper") as demo:
|
|
| 47 |
|
| 48 |
output = gr.Textbox(label="Útskrift", lines=20)
|
| 49 |
|
| 50 |
-
# Click → transcribe + stop timer when finished
|
| 51 |
btn.click(
|
| 52 |
transcribe_single,
|
| 53 |
inputs=audio_in,
|
|
|
|
| 1 |
+
# app.py – FIXED: No waveform=True (works on old Gradio)
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
|
|
| 16 |
token=os.getenv("HF_TOKEN")
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# Fix old Whisper checkpoints
|
| 20 |
if not hasattr(pipe.model.generation_config, "lang_to_id") or pipe.model.generation_config.lang_to_id is None:
|
| 21 |
pipe.model.generation_config.lang_to_id = {"is": 50259}
|
| 22 |
pipe.model.generation_config.task_to_id = {"transcribe": 50359, "translate": 50358}
|
|
|
|
| 24 |
|
| 25 |
print("Módel tilbúið!")
|
| 26 |
|
| 27 |
+
@spaces.GPU(duration=180)
|
| 28 |
def transcribe_single(audio_path):
|
| 29 |
if not audio_path:
|
| 30 |
return None, "Hladdu upp hljóðskrá", "00:00"
|
| 31 |
|
| 32 |
result = pipe(audio_path, chunk_length_s=30, batch_size=8)
|
| 33 |
text = result["text"].strip()
|
| 34 |
+
return audio_path, text, None # Clear timer when done
|
| 35 |
|
| 36 |
with gr.Blocks(title="Íslenskt Whisper") as demo:
|
| 37 |
gr.Markdown("# Íslenskt Whisper – Mjög lágt WER")
|
| 38 |
gr.Markdown("Hladdu upp einni hljóðskrá (allt að 5 mín) → smelltu á Transcribe")
|
| 39 |
|
| 40 |
with gr.Row():
|
| 41 |
+
audio_in = gr.Audio(label="Hljóðskrá", type="filepath") # ← waveform=True fjarlægt
|
| 42 |
|
| 43 |
btn = gr.Button("Transcribe", variant="primary", size="lg")
|
| 44 |
|
|
|
|
| 47 |
|
| 48 |
output = gr.Textbox(label="Útskrift", lines=20)
|
| 49 |
|
|
|
|
| 50 |
btn.click(
|
| 51 |
transcribe_single,
|
| 52 |
inputs=audio_in,
|