Hildah-N commited on
Commit
dcc06f1
·
verified ·
1 Parent(s): 5f13791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -29
app.py CHANGED
@@ -181,9 +181,6 @@ def _friendly_error(e: Exception) -> str:
181
  def process(input_mode, text_input, audio_input, target_language):
182
  """
183
  Called when the user clicks Generate.
184
- The first yield immediately clears stale output and wakes up Gradio's
185
- streaming so all subsequent yields (including errors) render on the
186
- very first click.
187
  """
188
  print("TOKEN SET:", bool(os.environ.get("SUNBIRD_API_TOKEN")))
189
  print(f"\n=== PROCESS CALLED ===")
@@ -192,32 +189,28 @@ def process(input_mode, text_input, audio_input, target_language):
192
  print(f"Audio input: {audio_input}")
193
  print(f"Target language: {target_language}")
194
 
195
- # ── Wake-up yield: clears stale results, enables immediate rendering ──
196
- yield ("", "", "", None, gr.update(value="", visible=False))
197
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  try:
199
- use_audio = (input_mode == "Audio Upload")
200
-
201
- if use_audio and not audio_input:
202
- yield (
203
- "",
204
- "",
205
- "",
206
- None,
207
- gr.update(value="<div id='error-box'>Please upload an audio file before running the pipeline.</div>", visible=True),
208
- )
209
- return
210
-
211
- if not use_audio and not (text_input and text_input.strip()):
212
- yield (
213
- "",
214
- "",
215
- "",
216
- None,
217
- gr.update(value="<div id='error-box'>Please enter some text before running the pipeline.</div>", visible=True),
218
- )
219
- return
220
-
221
  audio_path = audio_input if use_audio else None
222
  user_text = None if use_audio else text_input
223
 
@@ -235,6 +228,7 @@ def process(input_mode, text_input, audio_input, target_language):
235
  tmp.close()
236
  print(f"Audio saved to: {tmp.name}")
237
 
 
238
  yield (
239
  transcript,
240
  summary,
@@ -250,6 +244,8 @@ def process(input_mode, text_input, audio_input, target_language):
250
  traceback.print_exc()
251
 
252
  error_msg = _friendly_error(e)
 
 
253
  yield (
254
  "",
255
  "",
@@ -258,7 +254,6 @@ def process(input_mode, text_input, audio_input, target_language):
258
  gr.update(value=f"<div id='error-box'>{error_msg}</div>", visible=True),
259
  )
260
 
261
-
262
  # ── Build Gradio UI ──────────────────────────────────────────────────────────
263
 
264
  def build_ui():
 
181
  def process(input_mode, text_input, audio_input, target_language):
182
  """
183
  Called when the user clicks Generate.
 
 
 
184
  """
185
  print("TOKEN SET:", bool(os.environ.get("SUNBIRD_API_TOKEN")))
186
  print(f"\n=== PROCESS CALLED ===")
 
189
  print(f"Audio input: {audio_input}")
190
  print(f"Target language: {target_language}")
191
 
192
+ use_audio = (input_mode == "Audio Upload")
193
+
194
+ # Clear previous results - but don't yield if we're about to error
195
+ clear_yield = ("", "", "", None, gr.update(value="", visible=False))
196
+
197
+ # Validate inputs
198
+ if use_audio and not audio_input:
199
+ error_yield = ("", "", "", None, gr.update(value="<div id='error-box'>Please upload an audio file before running the pipeline.</div>", visible=True))
200
+ yield clear_yield
201
+ yield error_yield
202
+ return
203
+
204
+ if not use_audio and not (text_input and text_input.strip()):
205
+ error_yield = ("", "", "", None, gr.update(value="<div id='error-box'>Please enter some text before running the pipeline.</div>", visible=True))
206
+ yield clear_yield
207
+ yield error_yield
208
+ return
209
+
210
+ # Now yield the clear
211
+ yield clear_yield
212
+
213
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  audio_path = audio_input if use_audio else None
215
  user_text = None if use_audio else text_input
216
 
 
228
  tmp.close()
229
  print(f"Audio saved to: {tmp.name}")
230
 
231
+ # Final yield with results
232
  yield (
233
  transcript,
234
  summary,
 
244
  traceback.print_exc()
245
 
246
  error_msg = _friendly_error(e)
247
+ # Multiple yields to ensure error appears
248
+ yield ("", "", "", None, gr.update(value="", visible=False))
249
  yield (
250
  "",
251
  "",
 
254
  gr.update(value=f"<div id='error-box'>{error_msg}</div>", visible=True),
255
  )
256
 
 
257
  # ── Build Gradio UI ──────────────────────────────────────────────────────────
258
 
259
  def build_ui():