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

fix transcribe bug

Browse files
Files changed (2) hide show
  1. app.py +32 -21
  2. requirements.txt +4 -5
app.py CHANGED
@@ -5,7 +5,7 @@ from transformers import pipeline
5
 
6
  MODEL_NAME = "palli23/whisper-small-sam_spjall"
7
 
8
- print("Hleð módel...")
9
 
10
  pipe = pipeline(
11
  "automatic-speech-recognition",
@@ -15,25 +15,36 @@ pipe = pipeline(
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"))
 
5
 
6
  MODEL_NAME = "palli23/whisper-small-sam_spjall"
7
 
8
+ print("Hleð Whisper small (T4 small – engin takmörk)")
9
 
10
  pipe = pipeline(
11
  "automatic-speech-recognition",
 
15
  token=os.getenv("HF_TOKEN")
16
  )
17
 
18
+ # Þarf ekki lengur laga gamla config – nýja transformers gerir það sjálft
19
+ print("Módel tilbúið allt virkar!")
20
+
21
+ @spaces.GPU # engin duration þarf lengur – þú borgar fyrir tímann
22
+ def transcribe(audio_path):
23
+ if not audio_path:
24
+ return "Hladdu upp hljóðskrá"
25
+ result = pipe(audio_path, chunk_length_s=30, batch_size=16)
26
+ return result["text"].strip()
27
+
28
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
29
+ gr.Markdown("# Íslenskt Whisper – T4 small (mjög hratt & nákvæmt)")
30
+
31
+ with gr.Row():
32
+ audio = gr.Audio(
33
+ label="Hljóðskrá (allt 15 mín)",
34
+ type="filepath",
35
+ waveform=True, # virkar núna!
36
+ source="upload"
37
+ )
38
+
39
+ btn = gr.Button("Transcribe", variant="primary", size="lg")
40
+
41
+ with gr.Row():
42
+ timer = gr.Timer(label="Tími liðinn", active=True)
43
+
44
+ out = gr.Textbox(label="Útskrift", lines=28, show_copy_button=True)
45
+
46
+ btn.click(transcribe, audio, out).then(
47
+ lambda: gr.update(active=False), outputs=timer
48
+ )
49
 
50
  demo.launch(auth=("beta", "beta2025"))
requirements.txt CHANGED
@@ -1,6 +1,5 @@
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
 
1
+ gradio>=4.44
2
+ transformers>=4.45
3
+ torch>=2.4
 
4
  accelerate
5
+ spaces