reach-vb HF staff commited on
Commit
2050fe8
ยท
1 Parent(s): 4fb0807

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -54,20 +54,22 @@ css = """
54
  with gr.Blocks(css=css) as demo_blocks:
55
  gr.Markdown(title, elem_id="intro")
56
 
57
- with gr.Row():
58
  with gr.Column():
59
  inp_text = gr.Textbox(label="Input Prompt", info="What would you like MusicGen to synthesise?")
60
- btn = gr.Button("Generate Music!๐ŸŽถ")
61
 
62
  with gr.Column():
 
63
  out = gr.Audio(autoplay=False, label=f"Generated Music", show_label=True,)
64
 
65
-
66
- with gr.Accordion("Run MusicGen with Transformers ๐Ÿค—", open=False):
67
  gr.Markdown(
68
  """
 
69
  import torch
70
  import soundfile as sf
 
71
  from transformers import pipeline
72
 
73
  synthesiser = pipeline("text-to-audio",
@@ -75,14 +77,16 @@ with gr.Blocks(css=css) as demo_blocks:
75
  device="cuda:0",
76
  torch_dtype=torch.float16)
77
 
78
- music = synthesiser("lo-fi music with a soothing melody", forward_params={"max_new_tokens": 256})
 
79
 
80
  sf.write("musicgen_out.wav", music["audio"][0].T, music["sampling_rate"])
 
81
 
82
  """
83
  )
84
 
85
- btn.click(generate_audio, inp_text, out)
86
 
87
 
88
  demo_blocks.queue().launch()
 
54
  with gr.Blocks(css=css) as demo_blocks:
55
  gr.Markdown(title, elem_id="intro")
56
 
57
+ with gr.Row(elem_id="container"):
58
  with gr.Column():
59
  inp_text = gr.Textbox(label="Input Prompt", info="What would you like MusicGen to synthesise?")
60
+ btn = gr.Button("Generate Music! ๐ŸŽถ")
61
 
62
  with gr.Column():
63
+ out_vid = gr.make_waveform(animate=True, label=f"Generated Music", show_label=True)
64
  out = gr.Audio(autoplay=False, label=f"Generated Music", show_label=True,)
65
 
66
+ with gr.Accordion("Use MusicGen with Transformers ๐Ÿค—", open=False):
 
67
  gr.Markdown(
68
  """
69
+ ```python
70
  import torch
71
  import soundfile as sf
72
+
73
  from transformers import pipeline
74
 
75
  synthesiser = pipeline("text-to-audio",
 
77
  device="cuda:0",
78
  torch_dtype=torch.float16)
79
 
80
+ music = synthesiser("lo-fi music with a soothing melody",
81
+ forward_params={"max_new_tokens": 256})
82
 
83
  sf.write("musicgen_out.wav", music["audio"][0].T, music["sampling_rate"])
84
+ ```
85
 
86
  """
87
  )
88
 
89
+ btn.click(generate_audio, inp_text, [out_vid, out])
90
 
91
 
92
  demo_blocks.queue().launch()