nakas commited on
Commit
ef35140
1 Parent(s): 2f6da70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -98
app.py CHANGED
@@ -206,106 +206,101 @@ def toggle_audio_src(choice):
206
 
207
 
208
  def ui_full(launch_kwargs):
209
- with gr.Blocks() as interface:
210
- gr.Markdown(
211
- """
212
- # MusicGen
213
- This is your private demo for [MusicGen](https://github.com/facebookresearch/audiocraft),
214
- a simple and controllable model for music generation
215
- presented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284)
216
- """
217
- )
218
- with gr.Row():
219
- with gr.Column():
220
- with gr.Row():
221
- text = gr.Text(label="Input Text", interactive=True)
222
- with gr.Column():
223
- radio = gr.Radio(["file", "mic"], value="file",
224
- label="Condition on a melody (optional) File or Mic")
225
- melody = gr.Audio(source="upload", type="numpy", label="File",
226
- interactive=True, elem_id="melody-input")
227
- with gr.Row():
228
- submit = gr.Button("Submit")
229
- with gr.Row():
230
- model = gr.Radio(["melody", "medium", "small", "large"],
231
- label="Model", value="melody", interactive=True)
232
- with gr.Row():
233
- duration = gr.Slider(minimum=1, maximum=120, value=10, label="Duration", interactive=True)
234
- with gr.Row():
235
- topk = gr.Number(label="Top-k", value=250, interactive=True)
236
- topp = gr.Number(label="Top-p", value=0, interactive=True)
237
- temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
238
- cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
239
- with gr.Column():
240
- output = [
241
- gr.Audio(label=f"Generated Music {i+1}")
242
- for i in range(len(files))
243
- ]
244
- output_area = gr.Output(output)
245
-
246
- submit.click(predict_full,
247
- inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef],
248
- outputs=[output_area.value]) # Use value attribute of output_area
249
- radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
250
- gr.Examples(
251
- fn=predict_full,
252
- examples=[
253
- [
254
- "An 80s driving pop song with heavy drums and synth pads in the background",
255
- "./assets/bach.mp3",
256
- "melody"
257
- ],
258
- [
259
- "A cheerful country song with acoustic guitars",
260
- "./assets/bolero_ravel.mp3",
261
- "melody"
262
- ],
263
- [
264
- "90s rock song with electric guitar and heavy drums",
265
- None,
266
- "medium"
267
- ],
268
- [
269
- "a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions",
270
- "./assets/bach.mp3",
271
- "melody"
272
- ],
273
- [
274
- "lofi slow bpm electro chill with organic samples",
275
- None,
276
- "medium",
277
- ],
278
  ],
279
- inputs=[text, melody, model],
280
- outputs=[output_area.value], # Use value attribute of output_area
281
- )
282
- gr.Markdown(
283
- """
284
- ### More details
285
- The model will generate a short music extract based on the description you provided.
286
- The model can generate up to 30 seconds of audio in one pass. It is now possible
287
- to extend the generation by feeding back the end of the previous chunk of audio.
288
- This can take a long time, and the model might lose consistency. The model might also
289
- decide at arbitrary positions that the song ends.
290
- **WARNING:** Choosing long durations will take a long time to generate (2min might take ~10min).
291
- An overlap of 12 seconds is kept with the previously generated chunk, and 18 "new" seconds
292
- are generated each time.
293
- We present 4 model variations:
294
- 1. Melody -- a music generation model capable of generating music condition
295
- on text and melody inputs. **Note**, you can also use text only.
296
- 2. Small -- a 300M transformer decoder conditioned on text only.
297
- 3. Medium -- a 1.5B transformer decoder conditioned on text only.
298
- 4. Large -- a 3.3B transformer decoder conditioned on text only (might OOM for the longest sequences.)
299
- When using `melody`, ou can optionaly provide a reference audio from
300
- which a broad melody will be extracted. The model will then try to follow both
301
- the description and melody provided.
302
- You can also use your own GPU or a Google Colab by following the instructions on our repo.
303
- See [github.com/facebookresearch/audiocraft](https://github.com/facebookresearch/audiocraft)
304
- for more details.
305
- """
306
- )
307
 
308
- interface.queue().launch(**launch_kwargs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
 
310
 
311
  def ui_batched(launch_kwargs):
 
206
 
207
 
208
  def ui_full(launch_kwargs):
209
+ interface = gr.Interface(
210
+ fn=predict_full,
211
+ inputs=[
212
+ gr.Radio(["melody", "medium", "small", "large"], label="Model", default="melody"),
213
+ gr.Text(label="Input Text"),
214
+ gr.Audio(source="upload", type="numpy", label="File", interactive=True, elem_id="melody-input"),
215
+ gr.Slider(minimum=1, maximum=120, default=10, label="Duration", step=1),
216
+ gr.Number(label="Top-k", default=250),
217
+ gr.Number(label="Top-p", default=0),
218
+ gr.Number(label="Temperature", default=1.0),
219
+ gr.Number(label="Classifier Free Guidance", default=3.0),
220
+ ],
221
+ outputs=[
222
+ gr.Audio(label=f"Generated Music {i+1}") for i in range(len(files))
223
+ ],
224
+ title="MusicGen",
225
+ description="This is your private demo for MusicGen, a simple and controllable model for music generation.",
226
+ examples=[
227
+ [
228
+ "An 80s driving pop song with heavy drums and synth pads in the background",
229
+ "./assets/bach.mp3",
230
+ "melody"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  ],
232
+ [
233
+ "A cheerful country song with acoustic guitars",
234
+ "./assets/bolero_ravel.mp3",
235
+ "melody"
236
+ ],
237
+ [
238
+ "90s rock song with electric guitar and heavy drums",
239
+ None,
240
+ "medium"
241
+ ],
242
+ [
243
+ "a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions",
244
+ "./assets/bach.mp3",
245
+ "melody"
246
+ ],
247
+ [
248
+ "lofi slow bpm electro chill with organic samples",
249
+ None,
250
+ "medium",
251
+ ],
252
+ ],
253
+ allow_flagging=False,
254
+ layout="vertical",
255
+ **launch_kwargs
256
+ )
 
 
 
257
 
258
+ interface.launch()
259
+
260
+
261
+ if __name__ == "__main__":
262
+ parser = argparse.ArgumentParser()
263
+ parser.add_argument(
264
+ '--listen',
265
+ type=str,
266
+ default='0.0.0.0' if 'SPACE_ID' in os.environ else '127.0.0.1',
267
+ help='IP to listen on for connections to Gradio',
268
+ )
269
+ parser.add_argument(
270
+ '--username', type=str, default='', help='Username for authentication'
271
+ )
272
+ parser.add_argument(
273
+ '--password', type=str, default='', help='Password for authentication'
274
+ )
275
+ parser.add_argument(
276
+ '--server_port',
277
+ type=int,
278
+ default=0,
279
+ help='Port to run the server listener on',
280
+ )
281
+ parser.add_argument(
282
+ '--inbrowser', action='store_true', help='Open in browser'
283
+ )
284
+ parser.add_argument(
285
+ '--share', action='store_true', help='Share the gradio UI'
286
+ )
287
+
288
+ args = parser.parse_args()
289
+
290
+ launch_kwargs = {}
291
+ launch_kwargs['server_name'] = args.listen
292
+
293
+ if args.username and args.password:
294
+ launch_kwargs['auth'] = (args.username, args.password)
295
+ if args.server_port:
296
+ launch_kwargs['server_port'] = args.server_port
297
+ if args.inbrowser:
298
+ launch_kwargs['inbrowser'] = args.inbrowser
299
+ if args.share:
300
+ launch_kwargs['share'] = args.share
301
+
302
+ # Show the interface
303
+ ui_full(launch_kwargs)
304
 
305
 
306
  def ui_batched(launch_kwargs):