amedcj commited on
Commit
d33dce2
Β·
verified Β·
1 Parent(s): 4394250

Update app.py

Browse files

Updated app.py

Files changed (1) hide show
  1. app.py +62 -56
app.py CHANGED
@@ -1,56 +1,62 @@
1
- import gradio as gr
2
- import numpy as np
3
-
4
- from transformers import (
5
- pipeline,
6
- WhisperForConditionalGeneration,
7
- AutoTokenizer,
8
- WhisperFeatureExtractor,
9
- GenerationConfig
10
- )
11
-
12
- print("πŸ”§ Loading ASR components...")
13
-
14
- # Load generation config and remove forced_decoder_ids
15
- gen_config = GenerationConfig.from_pretrained("amedcj/whisper-kurmanji")
16
- gen_config.forced_decoder_ids = None
17
-
18
- # Load model and set generation config directly
19
- model = WhisperForConditionalGeneration.from_pretrained("amedcj/whisper-kurmanji")
20
- model.generation_config = gen_config
21
-
22
- # Load tokenizer and feature extractor
23
- tokenizer = AutoTokenizer.from_pretrained("amedcj/whisper-kurmanji")
24
- feature_extractor = WhisperFeatureExtractor.from_pretrained("amedcj/whisper-kurmanji")
25
-
26
- # Create the ASR pipeline
27
- asr = pipeline(
28
- "automatic-speech-recognition",
29
- model=model,
30
- tokenizer=tokenizer,
31
- feature_extractor=feature_extractor,
32
- device=-1 # CPU
33
- )
34
-
35
- def transcribe(audio_path):
36
- print("πŸ“₯ Transcription triggered")
37
- if audio_path is None:
38
- return "Please upload an audio file."
39
-
40
- array, sampling_rate = librosa.load(audio_path, sr=None)
41
- result = asr({"array": array, "sampling_rate": sampling_rate})
42
- return result["text"]
43
-
44
-
45
- # Gradio Interface using Blocks with a Submit button (compatible with HF Spaces)
46
- with gr.Blocks() as demo:
47
- gr.Markdown("## πŸ—£οΈ Kurdish ASR Demo")
48
-
49
- audio_input = gr.Audio(type="filepath", label="🎀 Upload Kurdish Audio")
50
- submit_btn = gr.Button("Submit")
51
- output_text = gr.Textbox(label="πŸ“ Transcription", interactive=False)
52
-
53
- submit_btn.click(fn=transcribe, inputs=audio_input, outputs=output_text)
54
-
55
- print("πŸš€ Launching Gradio app...")
56
- demo.launch()
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import sys
3
+
4
+ # Force upgrade gradio
5
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "gradio>=4.44.0"])
6
+
7
+ import gradio as gr
8
+ import numpy as np
9
+
10
+ from transformers import (
11
+ pipeline,
12
+ WhisperForConditionalGeneration,
13
+ AutoTokenizer,
14
+ WhisperFeatureExtractor,
15
+ GenerationConfig
16
+ )
17
+
18
+ print("πŸ”§ Loading ASR components...")
19
+
20
+ # Load generation config and remove forced_decoder_ids
21
+ gen_config = GenerationConfig.from_pretrained("amedcj/whisper-kurmanji")
22
+ gen_config.forced_decoder_ids = None
23
+
24
+ # Load model and set generation config directly
25
+ model = WhisperForConditionalGeneration.from_pretrained("amedcj/whisper-kurmanji")
26
+ model.generation_config = gen_config
27
+
28
+ # Load tokenizer and feature extractor
29
+ tokenizer = AutoTokenizer.from_pretrained("amedcj/whisper-kurmanji")
30
+ feature_extractor = WhisperFeatureExtractor.from_pretrained("amedcj/whisper-kurmanji")
31
+
32
+ # Create the ASR pipeline
33
+ asr = pipeline(
34
+ "automatic-speech-recognition",
35
+ model=model,
36
+ tokenizer=tokenizer,
37
+ feature_extractor=feature_extractor,
38
+ device=-1 # CPU
39
+ )
40
+
41
+ def transcribe(audio_path):
42
+ print("πŸ“₯ Transcription triggered")
43
+ if audio_path is None:
44
+ return "Please upload an audio file."
45
+
46
+ array, sampling_rate = librosa.load(audio_path, sr=None)
47
+ result = asr({"array": array, "sampling_rate": sampling_rate})
48
+ return result["text"]
49
+
50
+
51
+ # Gradio Interface using Blocks with a Submit button (compatible with HF Spaces)
52
+ with gr.Blocks() as demo:
53
+ gr.Markdown("## πŸ—£οΈ Kurdish ASR Demo")
54
+
55
+ audio_input = gr.Audio(type="filepath", label="🎀 Upload Kurdish Audio")
56
+ submit_btn = gr.Button("Submit")
57
+ output_text = gr.Textbox(label="πŸ“ Transcription", interactive=False)
58
+
59
+ submit_btn.click(fn=transcribe, inputs=audio_input, outputs=output_text)
60
+
61
+ print("πŸš€ Launching Gradio app...")
62
+ demo.launch()