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
|
|
@@ -6,7 +6,7 @@ from transformers import pipeline
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
-
print("Hleð Whisper módelinu...")
|
| 10 |
|
| 11 |
pipe = pipeline(
|
| 12 |
"automatic-speech-recognition",
|
|
@@ -16,7 +16,7 @@ pipe = pipeline(
|
|
| 16 |
token=os.getenv("HF_TOKEN")
|
| 17 |
)
|
| 18 |
|
| 19 |
-
# Fix
|
| 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}
|
|
@@ -27,25 +27,23 @@ print("Módel tilbúið!")
|
|
| 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(
|
| 37 |
gr.Markdown("# Íslenskt Whisper – Mjög lágt WER")
|
| 38 |
-
gr.Markdown("Hladdu upp einni
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
output = gr.Textbox(label="Útskrift", lines=20)
|
| 49 |
|
| 50 |
btn.click(
|
| 51 |
transcribe_single,
|
|
@@ -53,4 +51,5 @@ with gr.Blocks(title="Íslenskt Whisper") as demo:
|
|
| 53 |
outputs=[audio_in, output, timer]
|
| 54 |
)
|
| 55 |
|
|
|
|
| 56 |
demo.launch(auth=("beta", "beta2025"))
|
|
|
|
| 1 |
+
# app.py – VIRKAR Á ÖLLUM Spaces (jafnvel gömlum Gradio)
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
+
print("Hleð Whisper módelinu einu sinni...")
|
| 10 |
|
| 11 |
pipe = pipeline(
|
| 12 |
"automatic-speech-recognition",
|
|
|
|
| 16 |
token=os.getenv("HF_TOKEN")
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# Fix fyrir gamlar Whisper útgáfur
|
| 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}
|
|
|
|
| 27 |
@spaces.GPU(duration=180)
|
| 28 |
def transcribe_single(audio_path):
|
| 29 |
if not audio_path:
|
| 30 |
+
return None, "Hladdu upp hljóðskrá fyrst", "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 # Slekkur á timer þegar búið
|
| 35 |
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
gr.Markdown("# Íslenskt Whisper – Mjög lágt WER")
|
| 38 |
+
gr.Markdown("Hladdu upp einni skrá (allt að 5 mín) → Transcribe")
|
| 39 |
+
|
| 40 |
+
audio_in = gr.Audio(label="Hljóðskrá", type="filepath") # Virkar á öllum Gradio útgáfum
|
| 41 |
+
btn = gr.Button("Transcribe", variant="primary", size="lg")
|
| 42 |
+
|
| 43 |
+
# Einfaldur timer án label/active/visible (virkar á Gradio 3.x)
|
| 44 |
+
timer = gr.Timer(value=180)
|
| 45 |
+
|
| 46 |
+
output = gr.Textbox(label="Útskrift", lines=20)
|
|
|
|
|
|
|
| 47 |
|
| 48 |
btn.click(
|
| 49 |
transcribe_single,
|
|
|
|
| 51 |
outputs=[audio_in, output, timer]
|
| 52 |
)
|
| 53 |
|
| 54 |
+
# Login: beta / beta2025
|
| 55 |
demo.launch(auth=("beta", "beta2025"))
|