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,39 +6,38 @@ from transformers import pipeline
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
print("Hleð Whisper módelinu einu sinni...")
|
| 11 |
-
pipe = pipeline(
|
| 12 |
-
"automatic-speech-recognition",
|
| 13 |
-
model=MODEL_NAME,
|
| 14 |
-
torch_dtype="auto",
|
| 15 |
-
device_map="auto", # þetta er lykillinn fyrir ZeroGPU
|
| 16 |
-
token=os.getenv("HF_TOKEN")
|
| 17 |
-
)
|
| 18 |
-
print("Módel tilbúið!")
|
| 19 |
-
|
| 20 |
-
@spaces.GPU(duration=120) # 2 mínútur nægja fyrir 3–4 mín hljóð
|
| 21 |
def transcribe_3min(audio_path):
|
| 22 |
if not audio_path:
|
| 23 |
-
return "Hladdu upp hljóðskrá
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
result = pipe(
|
| 26 |
audio_path,
|
| 27 |
-
chunk_length_s=30,
|
| 28 |
-
|
| 29 |
return_timestamps=False,
|
| 30 |
-
|
| 31 |
)
|
|
|
|
| 32 |
return result["text"]
|
| 33 |
|
|
|
|
| 34 |
with gr.Blocks(title="Íslenskt ASR – 3 mín") as demo:
|
| 35 |
-
gr.Markdown("# Íslenskt
|
| 36 |
-
gr.Markdown("
|
| 37 |
|
| 38 |
-
|
| 39 |
-
btn = gr.Button("Transcribe", variant="primary")
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
btn.click(transcribe_3min, inputs=
|
| 43 |
|
| 44 |
-
demo.launch()
|
|
|
|
| 1 |
+
# app.py – 3 mín hljóð (ZeroGPU virkur, ekkert diarization)
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
|
|
| 6 |
|
| 7 |
MODEL_NAME = "palli23/whisper-small-sam_spjall"
|
| 8 |
|
| 9 |
+
@spaces.GPU(duration=60) # nóg fyrir 3 mín hljóð
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def transcribe_3min(audio_path):
|
| 11 |
if not audio_path:
|
| 12 |
+
return "Hladdu upp hljóðskrá"
|
| 13 |
+
|
| 14 |
+
# Whisper pipeline með chunking – ZeroGPU öruggt
|
| 15 |
+
pipe = pipeline(
|
| 16 |
+
"automatic-speech-recognition",
|
| 17 |
+
model=MODEL_NAME,
|
| 18 |
+
device=0,
|
| 19 |
+
token=os.getenv("HF_TOKEN")
|
| 20 |
+
)
|
| 21 |
|
| 22 |
result = pipe(
|
| 23 |
audio_path,
|
| 24 |
+
chunk_length_s=30, # 30 sek chunkar
|
| 25 |
+
stride_length_s=(6, 0), # 6 sek overlap
|
| 26 |
return_timestamps=False,
|
| 27 |
+
batch_size=8
|
| 28 |
)
|
| 29 |
+
|
| 30 |
return result["text"]
|
| 31 |
|
| 32 |
+
# Interface
|
| 33 |
with gr.Blocks(title="Íslenskt ASR – 3 mín") as demo:
|
| 34 |
+
gr.Markdown("# Íslenskt ASR – 3 mínútur")
|
| 35 |
+
gr.Markdown("**Whisper · Very low WER · 0.5-5minute audio transcribe á ZeroGPU**")
|
| 36 |
|
| 37 |
+
audio = gr.Audio(type="filepath", label="Hladdu upp .mp3 / .wav (allt að 3 mín)")
|
| 38 |
+
btn = gr.Button("Transcribe", variant="primary", size="lg")
|
| 39 |
+
out = gr.Textbox(lines=30, label="Útskrift")
|
| 40 |
+
|
| 41 |
+
btn.click(transcribe_3min, inputs=audio, outputs=out)
|
| 42 |
|
| 43 |
+
demo.launch(auth=("beta", "beta2025"))
|