jbilcke-hf HF staff commited on
Commit
758464e
1 Parent(s): ff38c5f

Update demos/musicgen_app.py

Browse files
Files changed (1) hide show
  1. demos/musicgen_app.py +15 -55
demos/musicgen_app.py CHANGED
@@ -241,7 +241,7 @@ def toggle_diffusion(choice):
241
  return [gr.update(visible=False)]
242
 
243
 
244
- def ui_full(launch_kwargs):
245
  with gr.Blocks() as interface:
246
  gr.Markdown(
247
  """
@@ -289,12 +289,13 @@ def ui_full(launch_kwargs):
289
  cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
290
  with gr.Column():
291
  audio_output = gr.Textbox(label="Generated Music (wav)")
292
- audio_diffusion = gr.Textbox(label="MultiBand Diffusion Decoder (wav)")
293
- submit.click(toggle_diffusion, decoder, [audio_diffusion], queue=False,
294
- show_progress=False).then(predict_full, inputs=[secret_token, model, model_path, decoder, text, melody, duration, topk, topp,
 
295
  temperature, cfg_coef],
296
- outputs=[audio_output])
297
- radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
298
 
299
  gr.Markdown(
300
  """
@@ -341,52 +342,11 @@ def ui_full(launch_kwargs):
341
  """
342
  )
343
 
344
- interface.queue().launch(**launch_kwargs)
345
-
346
- if __name__ == "__main__":
347
- parser = argparse.ArgumentParser()
348
- parser.add_argument(
349
- '--listen',
350
- type=str,
351
- default='0.0.0.0' if 'SPACE_ID' in os.environ else '127.0.0.1',
352
- help='IP to listen on for connections to Gradio',
353
- )
354
- parser.add_argument(
355
- '--username', type=str, default='', help='Username for authentication'
356
- )
357
- parser.add_argument(
358
- '--password', type=str, default='', help='Password for authentication'
359
- )
360
- parser.add_argument(
361
- '--server_port',
362
- type=int,
363
- default=0,
364
- help='Port to run the server listener on',
365
- )
366
- parser.add_argument(
367
- '--inbrowser', action='store_true', help='Open in browser'
368
- )
369
- parser.add_argument(
370
- '--share', action='store_true', help='Share the gradio UI'
371
- )
372
-
373
- args = parser.parse_args()
374
-
375
- launch_kwargs = {}
376
- launch_kwargs['server_name'] = args.listen
377
-
378
- if args.username and args.password:
379
- launch_kwargs['auth'] = (args.username, args.password)
380
- if args.server_port:
381
- launch_kwargs['server_port'] = args.server_port
382
- if args.inbrowser:
383
- launch_kwargs['inbrowser'] = args.inbrowser
384
- if args.share:
385
- launch_kwargs['share'] = args.share
386
-
387
- logging.basicConfig(level=logging.INFO, stream=sys.stderr)
388
-
389
- # Show the interface
390
- # we preload the model to avoid a timeout on the first request
391
- load_model('facebook/musicgen-stereo-large')
392
- ui_full(launch_kwargs)
 
241
  return [gr.update(visible=False)]
242
 
243
 
244
+ def ui_full():
245
  with gr.Blocks() as interface:
246
  gr.Markdown(
247
  """
 
289
  cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
290
  with gr.Column():
291
  audio_output = gr.Textbox(label="Generated Music (wav)")
292
+
293
+ submit.click(
294
+ fn=predict_full,
295
+ inputs=[secret_token, model, model_path, decoder, text, melody, duration, topk, topp,
296
  temperature, cfg_coef],
297
+ outputs=audio_output,
298
+ api_name="run")
299
 
300
  gr.Markdown(
301
  """
 
342
  """
343
  )
344
 
345
+ interface.queue(max_size=12).launch()
346
+
347
+ logging.basicConfig(level=logging.INFO, stream=sys.stderr)
348
+
349
+ # Show the interface
350
+ # we preload the model to avoid a timeout on the first request
351
+ load_model('facebook/musicgen-stereo-large')
352
+ ui_full()