akshansh36 commited on
Commit
2633321
1 Parent(s): afd359b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -19
app.py CHANGED
@@ -286,13 +286,30 @@ def index_conf():
286
  interactive=True,
287
  )
288
 
289
- def audio_conf():
290
- return gr.Audio(
291
- label="Upload or Record Audio",
292
- sources=["upload", "microphone"], # Allows recording via microphone
293
- type="filepath",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
- )
296
 
297
  def button_conf():
298
  return gr.Button(
@@ -307,31 +324,54 @@ def get_gui(theme):
307
  with gr.Blocks(theme=theme, delete_cache=(3200, 3200)) as app:
308
  gr.Markdown(title)
309
 
310
- aud = audio_conf()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  model = model_conf()
312
  indx = index_conf()
313
  button_base = button_conf()
314
  output_file, output_audio = output_conf()
315
 
 
 
 
316
  button_base.click(
317
  process_audio,
318
- inputs=[aud, model, indx],
319
  outputs=[output_file, output_audio],
320
  )
321
 
322
- gr.Examples(
323
- examples=[
324
- ["./test.ogg", "./model.pth", "./model.index"],
325
- ["./example2/test2.ogg", "./example2/model.pth", "./example2/model.index"],
326
- ],
327
- fn=process_audio,
328
- inputs=[aud, model, indx],
329
- outputs=[output_file, output_audio],
330
- cache_examples=False,
331
- )
332
-
333
  return app
334
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  if __name__ == "__main__":
336
  app = get_gui(theme)
337
  app.queue(default_concurrency_limit=40)
 
286
  interactive=True,
287
  )
288
 
289
+ # def audio_conf():
290
+ # return gr.Audio(
291
+ # label="Upload or Record Audio",
292
+ # sources=["upload", "microphone"], # Allows recording via microphone
293
+ # type="filepath",
294
+
295
+ # )
296
+
297
+
298
+ def get_audio_input(source_type):
299
+ if source_type == "Upload Audio File":
300
+ return gr.Files(
301
+ label="Upload Audio Files",
302
+ type="filepath",
303
+ file_count="multiple"
304
+ )
305
+ else:
306
+ return gr.Audio(
307
+ label="Record Audio",
308
+ sources=["microphone"],
309
+ type="filepath"
310
+ )
311
+
312
 
 
313
 
314
  def button_conf():
315
  return gr.Button(
 
324
  with gr.Blocks(theme=theme, delete_cache=(3200, 3200)) as app:
325
  gr.Markdown(title)
326
 
327
+ source_type = gr.Radio(
328
+ choices=["Upload Audio File", "Record Audio"],
329
+ label="Input Audio Type",
330
+ value="Upload Audio File",
331
+ interactive=True
332
+ )
333
+
334
+ audio_input = gr.State()
335
+
336
+ def update_audio_input(choice):
337
+ return get_audio_input(choice)
338
+
339
+ audio_input_component = gr.Column()
340
+
341
+ source_type.change(
342
+ update_audio_input,
343
+ inputs=source_type,
344
+ outputs=audio_input_component
345
+ )
346
+
347
  model = model_conf()
348
  indx = index_conf()
349
  button_base = button_conf()
350
  output_file, output_audio = output_conf()
351
 
352
+ with audio_input_component:
353
+ audio_input = get_audio_input("Upload Audio File") # Default
354
+
355
  button_base.click(
356
  process_audio,
357
+ inputs=[audio_input, model, indx],
358
  outputs=[output_file, output_audio],
359
  )
360
 
 
 
 
 
 
 
 
 
 
 
 
361
  return app
362
 
363
+ if __name__ == "__main__":
364
+ app = get_gui(theme)
365
+ app.queue(default_concurrency_limit=40)
366
+ app.launch(
367
+ max_threads=40,
368
+ share=False,
369
+ show_error=True,
370
+ quiet=False,
371
+ debug=False,
372
+ allowed_paths=["./downloads/"],
373
+ )
374
+
375
  if __name__ == "__main__":
376
  app = get_gui(theme)
377
  app.queue(default_concurrency_limit=40)