|
|
|
|
|
import os |
|
|
import gradio as gr |
|
|
import spaces |
|
|
from transformers import pipeline |
|
|
|
|
|
MODEL_NAME = "palli23/whisper-small-sam_spjall" |
|
|
|
|
|
|
|
|
print("Hleð Whisper módelinu einu sinni (tekur ~25 sek)...") |
|
|
pipe = pipeline( |
|
|
"automatic-speech-recognition", |
|
|
model=MODEL_NAME, |
|
|
torch_dtype="auto", |
|
|
device="cuda", |
|
|
token=os.getenv("HF_TOKEN", None) |
|
|
) |
|
|
|
|
|
|
|
|
if not hasattr(pipe.model.generation_config, "lang_to_id") or pipe.model.generation_config.lang_to_id is None: |
|
|
pipe.model.generation_config.lang_to_id = {"is": 50259} |
|
|
pipe.model.generation_config.task_to_id = {"transcribe": 50359, "translate": 50358} |
|
|
pipe.model.generation_config.forced_decoder_ids = None |
|
|
|
|
|
print("Módel tilbúið og lagfært!") |
|
|
|
|
|
|
|
|
@spaces.GPU(duration=60) |
|
|
def transcribe(audio_path): |
|
|
if not audio_path: |
|
|
return "Hladdu upp hljóðskrá fyrst" |
|
|
|
|
|
|
|
|
result = pipe(audio_path, chunk_length_s=30, batch_size=8) |
|
|
return result["text"].strip() |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# Íslenskt Whisper – Virkar núna") |
|
|
gr.Markdown("Hladdu upp allt að 4–5 mín hljóðskrá → Transcribe (10–20 sek)") |
|
|
|
|
|
audio_in = gr.Audio(type="filepath", label="Hljóðskrá") |
|
|
btn = gr.Button("Transcribe", variant="primary", size="lg") |
|
|
output = gr.Textbox(label="Útskrift", lines=25) |
|
|
|
|
|
btn.click(transcribe, inputs=audio_in, outputs=output) |
|
|
|
|
|
|
|
|
demo.launch(auth=("beta", "beta2025")) |