amedcj commited on
Commit
3e4448a
·
verified ·
1 Parent(s): 1e44bd2

Update app.py

Browse files

Updated app.py

Files changed (1) hide show
  1. app.py +51 -75
app.py CHANGED
@@ -1,8 +1,10 @@
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
  from transformers import (
@@ -18,12 +20,9 @@ print("🚀 Starting Kurmanji ASR application...")
18
 
19
  # Global variables
20
  asr = None
21
- model = None
22
- tokenizer = None
23
- feature_extractor = None
24
 
25
  def load_asr_model():
26
- global asr, model, tokenizer, feature_extractor
27
 
28
  try:
29
  print("📥 Loading Whisper model for Kurmanji...")
@@ -101,76 +100,53 @@ def transcribe(audio_file):
101
  traceback.print_exc()
102
  return error_msg
103
 
 
 
 
104
  # Create Gradio interface with Kurdish elements
105
  print("🎨 Creating Gradio interface...")
106
 
107
- with gr.Blocks(title="Kurmancî ASR - Kurdish Speech Recognition") as demo:
108
-
109
- gr.Markdown("""
110
- # 🗣️ Kurmancî ASR - Kurdish Speech Recognition
111
- ### Deng bo Nivîs / Speech to Text
112
-
113
- Dengê xwe bi Kurmancî tomar bike û wekî nivîs bibîne.
114
- Record your voice in Kurmanji Kurdish and convert it to text.
115
- """)
116
-
117
- with gr.Row():
118
- with gr.Column():
119
- audio_input = gr.Audio(
120
- sources=["microphone", "upload"], # Enable both mic recording and file upload
121
- type="filepath",
122
- label="🎤 Dengî tomar bike yan dosyeyekê lê bar bike / Record Voice or Upload File"
123
- )
124
-
125
- submit_btn = gr.Button(
126
- "Veguherîne / Transcribe",
127
- variant="primary",
128
- size="lg"
129
- )
130
-
131
- clear_btn = gr.Button(
132
- "Paqij Bike / Clear",
133
- variant="secondary"
134
- )
135
-
136
- with gr.Column():
137
- output_text = gr.Textbox(
138
- label="📝 Encam / Result",
139
- placeholder="Li virê dê nivîsa veguherandî xuya bibe... / Transcribed text will appear here...",
140
- lines=10,
141
- interactive=True, # Allow users to edit the result
142
- show_copy_button=True
143
- )
144
-
145
- # Add examples section
146
- gr.Markdown("### 💡 Mînak / Examples")
147
- gr.Markdown("""
148
- **Çawa bikar bînin / How to use:**
149
- 1. **Tomar bikin / Record:** Li ser butona mîkrofonê bitikînin û axaftin dest pê bikin
150
- 2. **An dosye bar bikin / Or upload:** Dosyeyek dengî (.wav, .mp3, .m4a) hilbijêrin
151
- 3. **Wergerînin / Transcribe:** Li ser "Wergerîne" bitikînin
152
-
153
- **Supported formats:** WAV, MP3, M4A, FLAC
154
- """)
155
-
156
- # Event handlers
157
- submit_btn.click(
158
- fn=transcribe,
159
- inputs=audio_input,
160
- outputs=output_text,
161
- show_progress=True
162
- )
163
 
164
- clear_btn.click(
165
- fn=lambda: (None, ""),
166
- inputs=[],
167
- outputs=[audio_input, output_text]
168
- )
169
-
170
- # Auto-transcribe when audio is recorded/uploaded (optional)
171
- audio_input.change(
172
- fn=transcribe,
173
- inputs=audio_input,
174
- outputs=output_text,
175
- show_progress=True
176
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import subprocess
2
  import sys
3
 
4
+ # Force upgrade gradio (only for Hugging Face)
5
+ import os
6
+ if "SPACE_ID" in os.environ:
7
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "gradio>=4.44.0"])
8
 
9
  import gradio as gr
10
  from transformers import (
 
20
 
21
  # Global variables
22
  asr = None
 
 
 
23
 
24
  def load_asr_model():
25
+ global asr
26
 
27
  try:
28
  print("📥 Loading Whisper model for Kurmanji...")
 
100
  traceback.print_exc()
101
  return error_msg
102
 
103
+ def clear_inputs():
104
+ return None, ""
105
+
106
  # Create Gradio interface with Kurdish elements
107
  print("🎨 Creating Gradio interface...")
108
 
109
+ demo = gr.Interface(
110
+ fn=transcribe,
111
+ inputs=gr.Audio(
112
+ sources=["microphone", "upload"],
113
+ type="filepath",
114
+ label="🎤 Deng Tomar Bike an Dosye Bar Bike / Record Voice or Upload File"
115
+ ),
116
+ outputs=gr.Textbox(
117
+ label="📝 Encam / Result",
118
+ placeholder="Li vir nivîsa wergerandî dê xuya bibe... / Transcribed text will appear here...",
119
+ lines=5,
120
+ show_copy_button=True
121
+ ),
122
+ title="🗣️ Kurmancî ASR - Kurdish Speech Recognition",
123
+ description="""
124
+ **Deng bo Nivîs / Speech to Text**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ **Formatên çêdibin:** WAV, MP3, M4A, FLAC
127
+ """,
128
+ submit_btn="Wergerîne / Transcribe",
129
+ clear_btn="Paqij Bike / Clear",
130
+ examples=[
131
+ # You can add example audio files here if you have them
132
+ # ["path/to/example1.wav"],
133
+ # ["path/to/example2.mp3"],
134
+ ],
135
+ cache_examples=False
136
+ )
137
+
138
+ print("🚀 Launching Gradio app...")
139
+
140
+ if __name__ == "__main__":
141
+ try:
142
+ demo.launch(
143
+ share=False,
144
+ server_name="127.0.0.1",
145
+ server_port=7860,
146
+ show_error=True,
147
+ inbrowser=True, # This will automatically open browser
148
+ debug=True
149
+ )
150
+ except Exception as e:
151
+ print(f"❌ Error launching interface: {e}")
152
+ traceback.print_exc()