akshansh36 commited on
Commit
e63a21f
1 Parent(s): f09f1a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import os
2
  import gradio as gr
3
  import spaces
@@ -255,10 +257,13 @@ def run(audio_files, file_m, file_index):
255
 
256
 
257
  def process_audio(audio_files, file_m, file_index):
258
- result = run(audio_files, file_m, file_index)
259
- return result # Only return the processed results
260
-
261
-
 
 
 
262
 
263
 
264
  def model_conf():
@@ -293,32 +298,23 @@ def button_conf():
293
  variant="primary",
294
  )
295
 
296
-
297
- # def output_conf():
298
- # return gr.File(label="Result", file_count="multiple", interactive=False), gr.Column(visible=False)
299
-
300
 
301
  def get_gui(theme):
302
- with gr.Blocks(theme=theme) as app:
303
  gr.Markdown(title)
304
 
305
  aud = audio_conf()
306
  model = model_conf()
307
  indx = index_conf()
308
  button_base = button_conf()
309
- output_audio = gr.Column(visible=True) # This will hold dynamically created audio components
310
-
311
- def display_audio_files(audio_paths):
312
- audio_components = []
313
- for audio_path in audio_paths:
314
- audio_components.append(gr.Audio(value=audio_path, label=os.path.basename(audio_path), visible=True))
315
- return audio_components
316
 
317
  button_base.click(
318
- fn=process_audio,
319
  inputs=[aud, model, indx],
320
- outputs=[output_audio],
321
- _js=display_audio_files # Function to dynamically create and display audio components
322
  )
323
 
324
  gr.Examples(
@@ -328,13 +324,12 @@ def get_gui(theme):
328
  ],
329
  fn=process_audio,
330
  inputs=[aud, model, indx],
331
- outputs=[output_audio],
332
  cache_examples=False,
333
  )
334
 
335
  return app
336
 
337
-
338
  if __name__ == "__main__":
339
  app = get_gui(theme)
340
  app.queue(default_concurrency_limit=40)
 
1
+
2
+
3
  import os
4
  import gradio as gr
5
  import spaces
 
257
 
258
 
259
  def process_audio(audio_files, file_m, file_index):
260
+ result, first_audio = run(audio_files, file_m, file_index)
261
+
262
+ # Ensure first_audio is correctly formatted as a valid file path
263
+ if not os.path.exists(first_audio):
264
+ raise ValueError(f"Processed audio file not found at: {first_audio}")
265
+
266
+ return result, gr.update(value=first_audio, visible=True)
267
 
268
 
269
  def model_conf():
 
298
  variant="primary",
299
  )
300
 
301
+ def output_conf():
302
+ return gr.File(label="Result", file_count="multiple", interactive=False), gr.Audio(label="Play Result",visible=False,show_share_button=False)
 
 
303
 
304
  def get_gui(theme):
305
+ with gr.Blocks(theme=theme, delete_cache=(3200, 3200)) as app:
306
  gr.Markdown(title)
307
 
308
  aud = audio_conf()
309
  model = model_conf()
310
  indx = index_conf()
311
  button_base = button_conf()
312
+ output_file, output_audio = output_conf()
 
 
 
 
 
 
313
 
314
  button_base.click(
315
+ process_audio,
316
  inputs=[aud, model, indx],
317
+ outputs=[output_file, output_audio],
 
318
  )
319
 
320
  gr.Examples(
 
324
  ],
325
  fn=process_audio,
326
  inputs=[aud, model, indx],
327
+ outputs=[output_file, output_audio],
328
  cache_examples=False,
329
  )
330
 
331
  return app
332
 
 
333
  if __name__ == "__main__":
334
  app = get_gui(theme)
335
  app.queue(default_concurrency_limit=40)