palli23 commited on
Commit
abc601d
·
1 Parent(s): edb0574

fix transcribe bug

Browse files
Files changed (2) hide show
  1. app.py +18 -28
  2. 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
- # ← Load model ONCE at startup (this is the key)
10
- print("Hleð Whisper módelinu einu sinni (tekur ~25 sek)...")
11
  pipe = pipeline(
12
  "automatic-speech-recognition",
13
  model=MODEL_NAME,
14
  torch_dtype="auto",
15
- device="cuda", # ZeroGPU always gives you a GPU
16
- token=os.getenv("HF_TOKEN", None)
17
  )
18
 
19
- # Fix old Whisper generation config (required for your checkpoint)
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}
23
  pipe.model.generation_config.forced_decoder_ids = None
24
 
25
- print("Módel tilbúið og lagfært!")
26
 
27
- # ← 60 seconds is more than enough because model is already loaded
28
- @spaces.GPU(duration=60)
29
- def transcribe(audio_path):
30
- if not audio_path:
31
- return "Hladdu upp hljóðskrá fyrst"
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 núna")
40
- gr.Markdown("Hladdu upp allt að 4–5 mín hljóðskrá → Transcribe (10–20 sek)")
41
-
42
- audio_in = gr.Audio(type="filepath", label="Hljóðskrá")
43
- btn = gr.Button("Transcribe", variant="primary", size="lg")
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 – ZERO errors, tested live
2
- gradio==4.44.0
3
- transformers==4.45.1
4
- torch==2.4.1
5
  spaces
6
- accelerate>=0.27.0
 
 
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