AvtnshM commited on
Commit
1602163
·
verified ·
1 Parent(s): 96f2af5
Files changed (1) hide show
  1. app.py +32 -17
app.py CHANGED
@@ -137,11 +137,28 @@ def transcribe_microphone(audio, language_choice, decoding_method):
137
  return "⚠️ कोई ऑडियो रिकॉर्ड नहीं हुआ। कृपया माइक्रोफ़ोन पर क्लिक करें और बोलें। (No audio recorded. Please click the microphone and speak.)"
138
  return transcribe_audio(audio, language_choice, decoding_method)
139
 
140
- def transcribe_file(audio_file, language_choice, decoding_method):
141
- """Transcribe uploaded audio file"""
142
- if audio_file is None:
143
- return "⚠️ कोई फ़ाइल अपलोडहीं हुई। ृपया ऑडियो फ़ाइचु (No file uploaded. Please select an audio file.)"
144
- return transcribe_audio(audio_file, language_choice, decoding_method)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  # Model status message
147
  model_status = "✅ Model loaded successfully!" if model is not None else "❌ Model failed to load"
@@ -209,7 +226,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
209
  with gr.Row():
210
  mic_submit_btn = gr.Button("🔄 ट्रांसक्राइब करें", variant="primary", size="lg")
211
  clear_mic_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
212
- copy_mic_btn = gr.Button("📋 कॉपी करें", variant="secondary")
213
 
214
  with gr.Column(scale=1):
215
  mic_output = gr.Textbox(
@@ -217,8 +234,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
217
  placeholder="रिकॉर्डिंग के बाद आपका ट्रांस्क्रिप्शन यहाँ दिखाई देगा...",
218
  lines=8,
219
  max_lines=15,
220
- interactive=True, # Enable text selection and copying
221
- show_copy_button=True # Add copy button
222
  )
223
 
224
  # Button actions for microphone tab
@@ -240,9 +256,9 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
240
  outputs=[microphone_input, mic_output]
241
  )
242
 
243
- # Copy functionality for microphone tab
244
- copy_mic_btn.click(
245
- lambda x: x, # Return the same text to enable copying
246
  inputs=mic_output,
247
  outputs=mic_output
248
  )
@@ -263,7 +279,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
263
  with gr.Row():
264
  file_submit_btn = gr.Button("🔄 फ़ाइल ट्रांसक्राइब करें", variant="primary", size="lg")
265
  clear_file_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
266
- copy_file_btn = gr.Button("📋 कॉपी करें", variant="secondary")
267
 
268
  with gr.Column(scale=1):
269
  file_output = gr.Textbox(
@@ -271,8 +287,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
271
  placeholder="एक ऑडियो फ़ाइल अपलोड करें और ट्रांसक्राइब पर क्लिक करें...",
272
  lines=8,
273
  max_lines=15,
274
- interactive=True, # Enable text selection and copying
275
- show_copy_button=True # Add copy button
276
  )
277
 
278
  # Button actions for file tab
@@ -287,9 +302,9 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
287
  outputs=[file_input, file_output]
288
  )
289
 
290
- # Copy functionality for file tab
291
- copy_file_btn.click(
292
- lambda x: x, # Return the same text to enable copying
293
  inputs=file_output,
294
  outputs=file_output
295
  )
 
137
  return "⚠️ कोई ऑडियो रिकॉर्ड नहीं हुआ। कृपया माइक्रोफ़ोन पर क्लिक करें और बोलें। (No audio recorded. Please click the microphone and speak.)"
138
  return transcribe_audio(audio, language_choice, decoding_method)
139
 
140
+ def create_shareable_text(text, method="Voice"):
141
+ """Create formatted text for sharing"""
142
+ if not text or text.strip() == "":
143
+ return "📤 कोई टेक्स्ट शेयर कर लिउपब्धहीहै।"
144
+
145
+ # Clean the text (remove markdown and emojis from result)
146
+ clean_text = text.replace("✅ **ट्रांस्क्रिप्शन (CTC):**", "").replace("✅ **ट्रांस्क्रिप्शन (RNNT):**", "")
147
+ clean_text = clean_text.strip()
148
+
149
+ # Create shareable format
150
+ share_text = f"""📱 Hindi Speech-to-Text Result
151
+
152
+ 🎙️ Input Method: {method}
153
+ 📝 Transcription: {clean_text}
154
+
155
+ 🤖 Generated by: AI4Bharat IndicConformer
156
+ 🌐 App: Hindi ASR - Hugging Face Spaces
157
+
158
+ ---
159
+ Share this Hindi transcription with others!"""
160
+
161
+ return share_text
162
 
163
  # Model status message
164
  model_status = "✅ Model loaded successfully!" if model is not None else "❌ Model failed to load"
 
226
  with gr.Row():
227
  mic_submit_btn = gr.Button("🔄 ट्रांसक्राइब करें", variant="primary", size="lg")
228
  clear_mic_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
229
+ share_mic_btn = gr.Button("📤 शेयर करें", variant="secondary")
230
 
231
  with gr.Column(scale=1):
232
  mic_output = gr.Textbox(
 
234
  placeholder="रिकॉर्डिंग के बाद आपका ट्रांस्क्रिप्शन यहाँ दिखाई देगा...",
235
  lines=8,
236
  max_lines=15,
237
+ interactive=True # Enable text selection
 
238
  )
239
 
240
  # Button actions for microphone tab
 
256
  outputs=[microphone_input, mic_output]
257
  )
258
 
259
+ # Share functionality for microphone tab
260
+ share_mic_btn.click(
261
+ fn=share_microphone_result,
262
  inputs=mic_output,
263
  outputs=mic_output
264
  )
 
279
  with gr.Row():
280
  file_submit_btn = gr.Button("🔄 फ़ाइल ट्रांसक्राइब करें", variant="primary", size="lg")
281
  clear_file_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
282
+ share_file_btn = gr.Button("📤 शेयर करें", variant="secondary")
283
 
284
  with gr.Column(scale=1):
285
  file_output = gr.Textbox(
 
287
  placeholder="एक ऑडियो फ़ाइल अपलोड करें और ट्रांसक्राइब पर क्लिक करें...",
288
  lines=8,
289
  max_lines=15,
290
+ interactive=True # Enable text selection
 
291
  )
292
 
293
  # Button actions for file tab
 
302
  outputs=[file_input, file_output]
303
  )
304
 
305
+ # Share functionality for file tab
306
+ share_file_btn.click(
307
+ fn=share_file_result,
308
  inputs=file_output,
309
  outputs=file_output
310
  )