Spaces:
Build error
Build error
Ashley Kleynhans commited on
Allow gradio command line arguments to be specified (#50)
Browse files6 unmodified lines7891011121314151644 unmodified lines6162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491506 unmodified lines"""from tempfile import NamedTemporaryFileimport torchimport gradio as grfrom audiocraft.models import MusicGenfrom audiocraft.data.audio import audio_write44 unmodified linesreturn waveform_videowith gr.Blocks() as demo:gr.Markdown("""# MusicGenThis is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft), a simple and controllable model for music generationpresented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).<br/><a href="https://huggingface.co/spaces/musicgen/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="Input Text", interactive=True)melody = gr.Audio(source="upload", type="numpy", label="Melody Condition (optional)", interactive=True)with gr.Row():submit = gr.Button("Submit")with gr.Row():model = gr.Radio(["melody", "medium", "small", "large"], label="Model", value="melody", interactive=True)with gr.Row():duration = gr.Slider(minimum=1, maximum=30, value=10, label="Duration", interactive=True)with gr.Row():topk = gr.Number(label="Top-k", value=250, interactive=True)topp = gr.Number(label="Top-p", value=0, interactive=True)temperature = gr.Number(label="Temperature", value=1.0, interactive=True)cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)with gr.Column():output = gr.Video(label="Generated Music")submit.click(predict, inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef], outputs=[output])gr.Examples(fn=predict,examples=[["An 80s driving pop song with heavy drums and synth pads in the background","./assets/bach.mp3","melody"],["A cheerful country song with acoustic guitars","./assets/bolero_ravel.mp3","melody"],["90s rock song with electric guitar and heavy drums",None,"medium"],["a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions","./assets/bach.mp3","melody"],["lofi slow bpm electro chill with organic samples",None,"medium",],],inputs=[text, melody, model],outputs=[output])gr.Markdown("""### More detailsThe model will generate a short music extract based on the description you provided.You can generate up to 30 seconds of audio.We present 4 model variations:1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.2. Small -- a 300M transformer decoder conditioned on text only.3. Medium -- a 1.5B transformer decoder conditioned on text only.4. Large -- a 3.3B transformer decoder conditioned on text only (might OOM for the longest sequences.)When using `melody`, ou can optionaly provide a reference audio fromwhich a broad melody will be extracted. The model will then try to follow both the description and melody provided.You can also use your own GPU or a Google Colab by following the instructions on our repo.See [github.com/facebookresearch/audiocraft](https://github.com/facebookresearch/audiocraft)for more details.""")demo.launch()6 unmodified lines7891011121314151644 unmodified lines6162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092106 unmodified lines"""from tempfile import NamedTemporaryFileimport argparseimport torchimport gradio as grfrom audiocraft.models import MusicGenfrom audiocraft.data.audio import audio_write44 unmodified linesreturn waveform_videodef ui(**kwargs):with gr.Blocks() as interface:gr.Markdown("""# MusicGenThis is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft), a simple and controllable model for music generationpresented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).<br/><a href="https://huggingface.co/spaces/musicgen/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="Input Text", interactive=True)melody = gr.Audio(source="upload", type="numpy", label="Melody Condition (optional)", interactive=True)with gr.Row():submit = gr.Button("Submit")with gr.Row():model = gr.Radio(["melody", "medium", "small", "large"], label="Model", value="melody", interactive=True)with gr.Row():duration = gr.Slider(minimum=1, maximum=30, value=10, label="Duration", interactive=True)with gr.Row():topk = gr.Number(label="Top-k", value=250, interactive=True)topp = gr.Number(label="Top-p", value=0, interactive=True)temperature = gr.Number(label="Temperature", value=1.0, interactive=True)cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)with gr.Column():output = gr.Video(label="Generated Music")submit.click(predict, inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef], outputs=[output])gr.Examples(fn=predict,examples=[["An 80s driving pop song with heavy drums and synth pads in the background","./assets/bach.mp3","melody"],["A cheerful country song with acoustic guitars","./assets/bolero_ravel.mp3","melody"],["90s rock song with electric guitar and heavy drums",None,"medium"],["a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions","./assets/bach.mp3","melody"],["lofi slow bpm electro chill with organic samples",None,"medium",],],inputs=[text, melody, model],outputs=[output])gr.Markdown("""### More detailsThe model will generate a short music extract based on the description you provided.You can generate up to 30 seconds of audio.We present 4 model variations:1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.2. Small -- a 300M transformer decoder conditioned on text only.3. Medium -- a 1.5B transformer decoder conditioned on text only.4. Large -- a 3.3B transformer decoder conditioned on text only (might OOM for the longest sequences.)When using `melody`, ou can optionaly provide a reference audio fromwhich a broad melody will be extracted. The model will then try to follow both the description and melody provided.You can also use your own GPU or a Google Colab by following the instructions on our repo.See [github.com/facebookresearch/audiocraft](https://github.com/facebookresearch/audiocraft)for more details.""")# Show the interfacelaunch_kwargs = {}username = kwargs.get('username')password = kwargs.get('password')server_port = kwargs.get('server_port', 0)inbrowser = kwargs.get('inbrowser', False)share = kwargs.get('share', False)server_name = kwargs.get('listen')launch_kwargs['server_name'] = server_nameif username and password:launch_kwargs['auth'] = (username, password)if server_port > 0:launch_kwargs['server_port'] = server_portif inbrowser:launch_kwargs['inbrowser'] = inbrowserif share:launch_kwargs['share'] = shareinterface.launch(**launch_kwargs)if __name__ == "__main__":# torch.cuda.set_per_process_memory_fraction(0.48)parser = argparse.ArgumentParser()parser.add_argument('--listen',type=str,default='127.0.0.1',help='IP to listen on for connections to Gradio',)parser.add_argument('--username', type=str, default='', help='Username for authentication')parser.add_argument('--password', type=str, default='', help='Password for authentication')parser.add_argument('--server_port',type=int,default=0,help='Port to run the server listener on',)parser.add_argument('--inbrowser', action='store_true', help='Open in browser')parser.add_argument('--share', action='store_true', help='Share the gradio UI')args = parser.parse_args()ui(username=args.username,password=args.password,inbrowser=args.inbrowser,server_port=args.server_port,share=args.share,listen=args.listen)
app.py+143-83