anzorq commited on
Commit
60a79e9
1 Parent(s): df65bb4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
2
+ import torch
3
+ import gradio as gr
4
+ import os
5
+ import numpy as np
6
+ from scipy.io.wavfile import read
7
+
8
+ os.system('git clone https://github.com/hmartiro/riffusion-inference.git riffusion')
9
+ os.system('cd riffusion-inference/riffusion')
10
+
11
+ repo_id = "riffusion/riffusion-model-v1"
12
+ pipe = DiffusionPipeline.from_pretrained(repo_id)
13
+
14
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
15
+ if torch.cuda.is_available():
16
+ pipe = pipe.to("cuda")
17
+
18
+ def infer(prompt, steps):
19
+
20
+ from riffusion.riffusion import audio
21
+
22
+ mel_spectr = pipe(prompt, num_inference_steps=steps).images[0]
23
+ wav_bytes, duration_s = audio.wav_bytes_from_spectrogram_image(mel_spectr)
24
+
25
+ return read(wav_bytes)
26
+
27
+ with gr.Blocks() as app:
28
+ gr.Markdown("## Riffusion Demo")
29
+ gr.Markdown("Generate audio clips from text prompts using the [Riffusion model](https://huggingface.co/riffusion/riffusion-model-v1).")
30
+ with gr.Group(elem_id='gr-interface'):
31
+ prompt = gr.Textbox(lines=1, label="Prompt")
32
+ steps = gr.Slider(minimum=1, maximum=100, value=25, label="Steps")
33
+ audio = gr.Audio(label="Audio")
34
+
35
+ btn_generate = gr.Button(value="Generate")
36
+
37
+ inputs = [prompt, steps]
38
+ outputs = [audio]
39
+
40
+ prompt.submit(infer, inputs, outputs)
41
+ btn_generate.click(infer, inputs, outputs)
42
+
43
+ examples = gr.Examples(
44
+ examples=[["rap battle freestyle"], ["techno club banger"], ["acoustic folk ballad"], ["blues guitar riff"], ["jazzy trumpet solo"], ["classical symphony orchestra"], ["rock and roll power chord"], ["soulful R&B love song"], ["reggae dub beat"], ["country western twangy guitar"], ["all 25 steps"]],
45
+ inputs=[prompt])
46
+
47
+ app.launch(debug=True, share=True)