jbilcke-hf HF staff commited on
Commit
a6a8a83
1 Parent(s): 5325fcc

Update demos/musicgen_app.py

Browse files
Files changed (1) hide show
  1. demos/musicgen_app.py +13 -72
demos/musicgen_app.py CHANGED
@@ -28,6 +28,7 @@ from audiocraft.data.audio import audio_write
28
  from audiocraft.models.encodec import InterleaveStereoCompressionModel
29
  from audiocraft.models import MusicGen, MultiBandDiffusion
30
 
 
31
 
32
  MODEL = None # Last used model
33
  SPACE_ID = os.environ.get('SPACE_ID', '')
@@ -178,7 +179,11 @@ def predict_batched(texts, melodies):
178
  return res
179
 
180
 
181
- def predict_full(model, model_path, decoder, text, melody, duration, topk, topp, temperature, cfg_coef, progress=gr.Progress()):
 
 
 
 
182
  global INTERRUPTING
183
  global USE_DIFFUSION
184
  INTERRUPTING = False
@@ -253,6 +258,11 @@ def ui_full(launch_kwargs):
253
  with gr.Row():
254
  with gr.Column():
255
  with gr.Row():
 
 
 
 
 
256
  text = gr.Text(label="Input Text", interactive=True)
257
  with gr.Column():
258
  radio = gr.Radio(["file", "mic"], value="file",
@@ -287,54 +297,11 @@ def ui_full(launch_kwargs):
287
  diffusion_output = gr.Video(label="MultiBand Diffusion Decoder")
288
  audio_diffusion = gr.Audio(label="MultiBand Diffusion Decoder (wav)", type='filepath')
289
  submit.click(toggle_diffusion, decoder, [diffusion_output, audio_diffusion], queue=False,
290
- show_progress=False).then(predict_full, inputs=[model, model_path, decoder, text, melody, duration, topk, topp,
291
  temperature, cfg_coef],
292
  outputs=[output, audio_output, diffusion_output, audio_diffusion])
293
  radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
294
 
295
- gr.Examples(
296
- fn=predict_full,
297
- examples=[
298
- [
299
- "An 80s driving pop song with heavy drums and synth pads in the background",
300
- "./assets/bach.mp3",
301
- "facebook/musicgen-stereo-melody",
302
- "Default"
303
- ],
304
- [
305
- "A cheerful country song with acoustic guitars",
306
- "./assets/bolero_ravel.mp3",
307
- "facebook/musicgen-stereo-melody",
308
- "Default"
309
- ],
310
- [
311
- "90s rock song with electric guitar and heavy drums",
312
- None,
313
- "facebook/musicgen-stereo-medium",
314
- "Default"
315
- ],
316
- [
317
- "a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions",
318
- "./assets/bach.mp3",
319
- "facebook/musicgen-stereo-melody",
320
- "Default"
321
- ],
322
- [
323
- "lofi slow bpm electro chill with organic samples",
324
- None,
325
- "facebook/musicgen-stereo-medium",
326
- "Default"
327
- ],
328
- [
329
- "Punk rock with loud drum and power guitar",
330
- None,
331
- "facebook/musicgen-stereo-medium",
332
- "MultiBand_Diffusion"
333
- ],
334
- ],
335
- inputs=[text, melody, model, decoder],
336
- outputs=[output]
337
- )
338
  gr.Markdown(
339
  """
340
  ### More details
@@ -417,33 +384,7 @@ def ui_batched(launch_kwargs):
417
  submit.click(predict_batched, inputs=[text, melody],
418
  outputs=[output, audio_output], batch=True, max_batch_size=MAX_BATCH_SIZE)
419
  radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
420
- gr.Examples(
421
- fn=predict_batched,
422
- examples=[
423
- [
424
- "An 80s driving pop song with heavy drums and synth pads in the background",
425
- "./assets/bach.mp3",
426
- ],
427
- [
428
- "A cheerful country song with acoustic guitars",
429
- "./assets/bolero_ravel.mp3",
430
- ],
431
- [
432
- "90s rock song with electric guitar and heavy drums",
433
- None,
434
- ],
435
- [
436
- "a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions bpm: 130",
437
- "./assets/bach.mp3",
438
- ],
439
- [
440
- "lofi slow bpm electro chill with organic samples",
441
- None,
442
- ],
443
- ],
444
- inputs=[text, melody],
445
- outputs=[output]
446
- )
447
  gr.Markdown("""
448
  ### More details
449
 
 
28
  from audiocraft.models.encodec import InterleaveStereoCompressionModel
29
  from audiocraft.models import MusicGen, MultiBandDiffusion
30
 
31
+ SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
32
 
33
  MODEL = None # Last used model
34
  SPACE_ID = os.environ.get('SPACE_ID', '')
 
179
  return res
180
 
181
 
182
+ def predict_full(secret_token, model, model_path, decoder, text, melody, duration, topk, topp, temperature, cfg_coef, progress=gr.Progress()):
183
+ if secret_token != SECRET_TOKEN:
184
+ raise gr.Error(
185
+ f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
186
+
187
  global INTERRUPTING
188
  global USE_DIFFUSION
189
  INTERRUPTING = False
 
258
  with gr.Row():
259
  with gr.Column():
260
  with gr.Row():
261
+ secret_token = gr.Text(
262
+ label='Secret Token',
263
+ max_lines=1,
264
+ placeholder='Enter your secret token'
265
+ )
266
  text = gr.Text(label="Input Text", interactive=True)
267
  with gr.Column():
268
  radio = gr.Radio(["file", "mic"], value="file",
 
297
  diffusion_output = gr.Video(label="MultiBand Diffusion Decoder")
298
  audio_diffusion = gr.Audio(label="MultiBand Diffusion Decoder (wav)", type='filepath')
299
  submit.click(toggle_diffusion, decoder, [diffusion_output, audio_diffusion], queue=False,
300
+ show_progress=False).then(predict_full, inputs=[secret_token, model, model_path, decoder, text, melody, duration, topk, topp,
301
  temperature, cfg_coef],
302
  outputs=[output, audio_output, diffusion_output, audio_diffusion])
303
  radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  gr.Markdown(
306
  """
307
  ### More details
 
384
  submit.click(predict_batched, inputs=[text, melody],
385
  outputs=[output, audio_output], batch=True, max_batch_size=MAX_BATCH_SIZE)
386
  radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
387
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  gr.Markdown("""
389
  ### More details
390