code: def ui_batched(launch_kwargs):
      with gr.Blocks() as demo:
          gr.Markdown(
              """
              # MusicGen
  
              This is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft/blob/main/docs/MUSICGEN.md),
              a simple and controllable model for music generation
              presented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).
              <br/>
              <a href="https://huggingface.co/spaces/facebook/MusicGen?duplicate=true"
                  style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
              <img style="margin-bottom: 0em;display: inline;margin-top: -.25em;"
                  src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
              for longer sequences, more control and no queue.</p>
              """
          )
          with gr.Row():
              with gr.Column():
                  with gr.Row():
                      text = gr.Text(
                          label="Describe your music",
                          lines=2,
                          interactive=True,
                      )
                      with gr.Column():
                          radio = gr.Radio(
                              ["file", "mic"],
                              value="file",
                              label="Condition on a melody (optional) File or Mic",
                          )
                          melody = gr.Audio(
                              source="upload",
                              type="numpy",
                              label="File",
                              interactive=True,
                              elem_id="melody-input",
                          )
                  with gr.Row():
                      submit = gr.Button("Generate")
              with gr.Column():
                  output = gr.Video(label="Generated Music")
                  audio_output = gr.Audio(
                      label="Generated Music (wav)", type="filepath"
                  )
          submit.click(
              predict_batched,
              inputs=[text, melody],
              outputs=[output, audio_output],
              batch=True,
              max_batch_size=MAX_BATCH_SIZE,
          )
          radio.change(
              toggle_audio_src,
              radio,
              [melody],
              queue=False,
              show_progress=False,
          )
          gr.Examples(
              fn=predict_batched,
              examples=[
                  [
                      "An 80s driving pop song with heavy drums and synth pads in the background",
                      "./assets/bach.mp3",
                  ],
                  [
                      "A cheerful country song with acoustic guitars",
                      "./assets/bolero_ravel.mp3",
                  ],
                  [
                      "90s rock song with electric guitar and heavy drums",
                      None,
                  ],
                  [
                      "a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions bpm: 130",
                      "./assets/bach.mp3",
                  ],
                  [
                      "lofi slow bpm electro chill with organic samples",
                      None,
                  ],
              ],
              inputs=[text, melody],
              outputs=[output],
          )
          gr.Markdown(
              """
          ### More details
  
          The model will generate 15 seconds of audio based on the description you provided.
          The model was trained with description from a stock music catalog, descriptions that will work best
          should include some level of details on the instruments present, along with some intended use case
          (e.g. adding "perfect for a commercial" can somehow help).
  
          You can optionally provide a reference audio from which a broad melody will be extracted.
          The model will then try to follow both the description and melody provided.
          For best results, the melody should be 30 seconds long (I know, the samples we provide are not...)
  
          You can access more control (longer generation, more models etc.) by clicking
          the <a href="https://huggingface.co/spaces/facebook/MusicGen?duplicate=true"
                  style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
              <img style="margin-bottom: 0em;display: inline;margin-top: -.25em;"
                  src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
          (you will then need a paid GPU from HuggingFace).
          If you have a GPU, you can run the gradio demo locally (click the link to our repo below for more info).
          Finally, you can get a GPU for free from Google
          and run the demo in [a Google Colab.](https://ai.honu.io/red/musicgen-colab).
  
          See [github.com/facebookresearch/audiocraft](https://github.com/facebookresearch/audiocraft/blob/main/docs/MUSICGEN.md)
          for more details. All samples are generated with the `stereo-melody` model.
          """
          )
  
          demo.queue(max_size=8 * 4).launch(**launch_kwargs)
  
imports: import argparse
  from concurrent.futures import ProcessPoolExecutor
  import logging
  import os
  from pathlib import Path
  import subprocess
  import sys
  from tempfile import NamedTemporaryFile
  import time
  import typing
  import warnings
  from einops import rearrange
  import torch
  import gradio
  from audiocraft.data.audio_utils import convert_audio
  from audiocraft.data.audio import audio_write
  from audiocraft.models.encodec import InterleaveStereoCompressionModel
  from audiocraft.models import MusicGen, MultiBandDiffusion
label_desc: Use image node_id 12 for calling a global function with example usage: ui_batched(launch_kwargs) without return types