Fauno15 akhaliq HF staff commited on
Commit
97bb0e0
1 Parent(s): f5a09e2

fix name and add dropdown (#5)

Browse files

- fix name and add dropdown (f2731e88fac625e7af7993b3d66e09d6034b71fb)


Co-authored-by: Ahsen Khaliq <akhaliq@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +52 -8
app.py CHANGED
@@ -1,15 +1,59 @@
1
  import gradio as gr
2
- import scipy
3
  from diffusers import DiffusionPipeline
 
4
 
5
- model_id = "harmonai/maestro-150k"
6
- pipeline = DiffusionPipeline.from_pretrained(model_id)
7
- pipeline = pipeline.to("cuda")
8
 
9
- def denoise(length_sec):
 
 
 
 
 
10
  audios = pipeline(audio_length_in_s=length_sec).audios
11
  for audio in audios:
12
- scipy.io.wavfile.write("maestro_test.wav", pipeline.unet.sample_rate, audio.transpose())
13
- return "maestro_test.wav"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- gr.Interface(fn=denoise, inputs=gr.Slider(1.0, 6.0, value=3.0, step=0.5, label="Audio length in seconds"), outputs="audio").launch()
 
1
  import gradio as gr
 
2
  from diffusers import DiffusionPipeline
3
+ import scipy.io.wavfile
4
 
 
 
 
5
 
6
+ def load_model(model_id):
7
+ pipeline = DiffusionPipeline.from_pretrained(model_id)
8
+ pipeline = pipeline.to("cuda")
9
+
10
+ def denoise(length_sec,model):
11
+ load_model(model)
12
  audios = pipeline(audio_length_in_s=length_sec).audios
13
  for audio in audios:
14
+ scipy.io.wavfile.write("test.wav", pipeline.unet.sample_rate, audio.transpose())
15
+ return "test.wav"
16
+
17
+
18
+
19
+
20
+ block = gr.Blocks()
21
+
22
+ with block:
23
+ gr.HTML(
24
+ """
25
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
26
+ <div
27
+ style="
28
+ display: inline-flex;
29
+ align-items: center;
30
+ gap: 0.8rem;
31
+ font-size: 1.75rem;
32
+ "
33
+ >
34
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
35
+ Dance Diffusion
36
+ </h1>
37
+ </div>
38
+ <p style="margin-bottom: 10px; font-size: 94%">
39
+ Dance Diffusion is the first in a suite of generative audio tools for producers and musicians to be released by Harmonai
40
+ </p>
41
+ </div>
42
+ """
43
+ )
44
+ with gr.Group():
45
+ with gr.Box():
46
+ length = gr.Slider(1.0, 6.0, value=3.0, step=0.5, label="Audio length in seconds")
47
+ 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")
48
+ out = gr.Audio(label="Output", type="filepath")
49
+ btn = gr.Button("Submit").style(full_width=True)
50
+
51
+ btn.click(denoise, inputs=[length,model], outputs=out)
52
+ gr.HTML('''
53
+ <div class="footer">
54
+ <p>Model by <a href="https://huggingface.co/harmonai" style="text-decoration: underline;" target="_blank">Harmonai</a>
55
+ </p>
56
+ </div>
57
+ ''')
58
 
59
+ block.launch(debug=True)