import gradio as gr from diffusers import DiffusionPipeline import scipy.io.wavfile def load_model(model_id): pipeline = DiffusionPipeline.from_pretrained(model_id) pipeline = pipeline.to("cuda") return pipeline def denoise(length_sec,model): pipeline = load_model(model) audios = pipeline(audio_length_in_s=length_sec).audios for audio in audios: scipy.io.wavfile.write("test.wav", pipeline.unet.sample_rate, audio.transpose()) return "test.wav" block = gr.Blocks() with block: gr.HTML( """

Dance Diffusion

Dance Diffusion is the first in a suite of generative audio tools for producers and musicians to be released by Harmonai

""" ) with gr.Group(): with gr.Box(): length = gr.Slider(1.0, 6.0, value=3.0, step=0.5, label="Audio length in seconds") model = gr.Dropdown(choices=["harmonai/maestro-150k", "harmonai/jmann-small-190k", "harmonai/honk-140k", "harmonai/unlocked-250k","harmonai/jmann-large-580k","harmonai/glitch-440k"], value="harmonai/maestro-150k",type="value", label="Model") out = gr.Audio(label="Output", type="filepath") btn = gr.Button("Submit").style(full_width=True) btn.click(denoise, inputs=[length,model], outputs=out) gr.HTML(''' ''') block.launch(debug=True)