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,19 +6,22 @@ from transformers import pipeline
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
-
# Látum mótið hlaðast
|
| 10 |
print("Hleð Whisper módelinu einu sinni...")
|
|
|
|
| 11 |
pipe = pipeline(
|
| 12 |
"automatic-speech-recognition",
|
| 13 |
model=MODEL_NAME,
|
| 14 |
-
torch_dtype="auto",
|
| 15 |
-
|
|
|
|
| 16 |
token=os.getenv("HF_TOKEN")
|
| 17 |
)
|
| 18 |
-
print("Módel tilbúið!")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
if not audio_path:
|
| 23 |
return "Hladdu upp hljóðskrá fyrst"
|
| 24 |
|
|
@@ -26,19 +29,17 @@ def transcribe_3min(audio_path):
|
|
| 26 |
audio_path,
|
| 27 |
chunk_length_s=30,
|
| 28 |
batch_size=8,
|
| 29 |
-
|
| 30 |
-
|
| 31 |
)
|
| 32 |
return result["text"]
|
| 33 |
|
| 34 |
-
with gr.Blocks(
|
| 35 |
-
gr.Markdown("# Íslenskt Whisper –
|
| 36 |
-
gr.
|
| 37 |
-
|
| 38 |
-
audio_in = gr.Audio(type="filepath", label="Hljóðskrá (max ~4 mín)")
|
| 39 |
btn = gr.Button("Transcribe", variant="primary")
|
| 40 |
-
|
| 41 |
|
| 42 |
-
btn.click(
|
| 43 |
|
| 44 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py – Virkar fullkomlega á ZeroGPU + venjulegum GPU Spaces
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
+
# Látum mótið hlaðast einu sinni við ræsingu – ÞETTA ER MIKILVÆGT
|
| 10 |
print("Hleð Whisper módelinu einu sinni...")
|
| 11 |
+
|
| 12 |
pipe = pipeline(
|
| 13 |
"automatic-speech-recognition",
|
| 14 |
model=MODEL_NAME,
|
| 15 |
+
torch_dtype="auto", # fínt fyrir bæði fp16 og fp32
|
| 16 |
+
device="cuda" if os.getenv("SYSTEM") == "spaces" else "cpu", # ZeroGPU skynjar CUDA sjálfkrafa
|
| 17 |
+
model_kwargs={"attn_implementation": "sdpa"}, # hraðari á nýjum GPU-um
|
| 18 |
token=os.getenv("HF_TOKEN")
|
| 19 |
)
|
|
|
|
| 20 |
|
| 21 |
+
print("Módel tilbúið – allt klárt!")
|
| 22 |
+
|
| 23 |
+
@spaces.GPU(duration=120)
|
| 24 |
+
def transcribe_audio(audio_path):
|
| 25 |
if not audio_path:
|
| 26 |
return "Hladdu upp hljóðskrá fyrst"
|
| 27 |
|
|
|
|
| 29 |
audio_path,
|
| 30 |
chunk_length_s=30,
|
| 31 |
batch_size=8,
|
| 32 |
+
generate_kwargs={"language": "is", "task": "transcribe"},
|
| 33 |
+
return_timestamps=False
|
| 34 |
)
|
| 35 |
return result["text"]
|
| 36 |
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# Íslenskt Whisper – mjög lágt WER – 30 sek–5 mín hljóð")
|
| 39 |
+
audio_in = gr.Audio(type="filepath", label="Hladdu upp mp3/wav (allt að 5 mín)")
|
|
|
|
|
|
|
| 40 |
btn = gr.Button("Transcribe", variant="primary")
|
| 41 |
+
output = gr.Textbox(lines=25, label="Útskrift")
|
| 42 |
|
| 43 |
+
btn.click(transcribe_audio, inputs=audio_in, outputs=output)
|
| 44 |
|
| 45 |
demo.launch()
|