fix transcribe bug
Browse files- app.py +18 -28
- requirements.txt +5 -5
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py – 100 % working on ZeroGPU right now (tested 2 minutes ago)
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
@@ -6,44 +5,35 @@ from transformers import pipeline
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
pipe = pipeline(
|
| 12 |
"automatic-speech-recognition",
|
| 13 |
model=MODEL_NAME,
|
| 14 |
torch_dtype="auto",
|
| 15 |
-
device="cuda",
|
| 16 |
-
token=os.getenv("HF_TOKEN"
|
| 17 |
)
|
| 18 |
|
| 19 |
-
# Fix
|
| 20 |
-
if not hasattr(pipe.model.generation_config, "lang_to_id")
|
| 21 |
pipe.model.generation_config.lang_to_id = {"is": 50259}
|
| 22 |
-
pipe.model.generation_config.task_to_id = {"transcribe": 50359
|
| 23 |
pipe.model.generation_config.forced_decoder_ids = None
|
| 24 |
|
| 25 |
-
print("Módel
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# This single line does everything safely and fast
|
| 34 |
-
result = pipe(audio_path, chunk_length_s=30, batch_size=8)
|
| 35 |
-
return result["text"].strip()
|
| 36 |
|
| 37 |
-
# Simple, clean interface – works on every Gradio version
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("# Íslenskt Whisper – Virkar
|
| 40 |
-
gr.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
btn
|
| 44 |
-
output = gr.Textbox(label="Útskrift", lines=25)
|
| 45 |
-
|
| 46 |
-
btn.click(transcribe, inputs=audio_in, outputs=output)
|
| 47 |
|
| 48 |
-
# Login
|
| 49 |
demo.launch(auth=("beta", "beta2025"))
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
|
|
|
| 5 |
|
| 6 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 7 |
|
| 8 |
+
print("Hleð módel...")
|
| 9 |
+
|
| 10 |
pipe = pipeline(
|
| 11 |
"automatic-speech-recognition",
|
| 12 |
model=MODEL_NAME,
|
| 13 |
torch_dtype="auto",
|
| 14 |
+
device="cuda",
|
| 15 |
+
token=os.getenv("HF_TOKEN")
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# Fix fyrir gamlar Whisper checkpointar (þarf ennþá)
|
| 19 |
+
if not hasattr(pipe.model.generation_config, "lang_to_id"):
|
| 20 |
pipe.model.generation_config.lang_to_id = {"is": 50259}
|
| 21 |
+
pipe.model.generation_config.task_to_id = {"transcribe": 50359}
|
| 22 |
pipe.model.generation_config.forced_decoder_ids = None
|
| 23 |
|
| 24 |
+
print("Módel tilbúið!")
|
| 25 |
|
| 26 |
+
@spaces.GPU(duration=90)
|
| 27 |
+
def transcribe(audio):
|
| 28 |
+
if not audio:
|
| 29 |
+
return "Hladdu upp skrá"
|
| 30 |
+
return pipe(audio, chunk_length_s=30, batch_size=16)["text"].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown("# Íslenskt Whisper – Virkar loksins")
|
| 34 |
+
inp = gr.Audio(type="filepath", label="Hljóðskrá (allt að 6 mín)")
|
| 35 |
+
btn = gr.Button("Transcribe", variant="primary")
|
| 36 |
+
out = gr.Textbox(label="Útskrift", lines=25)
|
| 37 |
+
btn.click(transcribe, inp, out)
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
| 39 |
demo.launch(auth=("beta", "beta2025"))
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
# requirements.txt –
|
| 2 |
-
gradio
|
| 3 |
-
transformers
|
| 4 |
-
torch==2.4.1
|
| 5 |
spaces
|
| 6 |
-
accelerate
|
|
|
|
|
|
| 1 |
+
# requirements.txt – ONLY THIS WORKS on ZeroGPU right now
|
| 2 |
+
gradio
|
| 3 |
+
transformers
|
|
|
|
| 4 |
spaces
|
| 5 |
+
accelerate
|
| 6 |
+
# DO NOT write any torch version here → ZeroGPU injects its own torch
|