File size: 1,907 Bytes
72c877e
 
 
 
c17b696
72c877e
d533c9c
 
 
 
 
 
 
 
 
 
72c877e
8c2e759
 
 
 
 
1dfb040
 
 
8c2e759
 
 
 
 
 
 
 
 
02a7301
8c2e759
 
 
 
 
 
 
 
02a7301
72c877e
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse

import gradio as gr

from audiodiffusion import AudioDiffusion


def generate_spectrogram_audio_and_loop(model_id):
    audio_diffusion = AudioDiffusion(model_id=model_id)
    image, (sample_rate,
            audio) = audio_diffusion.generate_spectrogram_and_audio()
    loop = AudioDiffusion.loop_it(audio, sample_rate)
    if loop is None:
        loop = audio
    return image, (sample_rate, audio), (sample_rate, loop)


demo = gr.Interface(
    fn=generate_spectrogram_audio_and_loop,
    title="Audio Diffusion",
    description="Generate audio using Huggingface diffusers.\
        The models without 'latent' or 'ddim' give better results but take about \
            20 minutes without a GPU. For GPU, you can use \
                [colab](https://colab.research.google.com/github/teticio/audio-diffusion/blob/master/notebooks/gradio_app.ipynb) \
                    to run this app.",
    inputs=[
        gr.Dropdown(label="Model",
                    choices=[
                        "teticio/audio-diffusion-256",
                        "teticio/audio-diffusion-breaks-256",
                        "teticio/audio-diffusion-instrumental-hiphop-256",
                        "teticio/audio-diffusion-ddim-256",
                        "teticio/latent-audio-diffusion-256",
                        "teticio/latent-audio-diffusion-ddim-256"
                    ],
                    value="teticio/latent-audio-diffusion-ddim-256")
    ],
    outputs=[
        gr.Image(label="Mel spectrogram", image_mode="L"),
        gr.Audio(label="Audio"),
        gr.Audio(label="Loop"),
    ],
    allow_flagging="never")

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", type=int)
    parser.add_argument("--server", type=int)
    args = parser.parse_args()
    demo.launch(server_name=args.server or "0.0.0.0", server_port=args.port)