Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import numpy as np
|
| 6 |
from spectro import wav_bytes_from_spectrogram_image
|
| 7 |
-
|
| 8 |
from diffusers import StableDiffusionPipeline
|
| 9 |
-
from diffusers import StableDiffusionImg2ImgPipeline
|
| 10 |
|
| 11 |
device = "cpu"
|
| 12 |
MODEL_ID = "Hyeon2/riffusion-musiccaps"
|
| 13 |
pipe = StableDiffusionPipeline.from_pretrained(MODEL_ID)
|
| 14 |
pipe = pipe.to(device)
|
| 15 |
|
| 16 |
-
def predict(prompt
|
| 17 |
-
|
| 18 |
-
width_duration=512
|
| 19 |
-
else:
|
| 20 |
-
width_duration = 512 + ((int(duration) - 5) * 128)
|
| 21 |
-
spec = pipe(prompt, height=512, width=width_duration).images[0]
|
| 22 |
print(spec)
|
| 23 |
wav = wav_bytes_from_spectrogram_image(spec)
|
| 24 |
with open("output.wav", "wb") as f:
|
|
@@ -47,81 +38,16 @@ title = """
|
|
| 47 |
</div>
|
| 48 |
"""
|
| 49 |
|
| 50 |
-
css = '''
|
| 51 |
-
#col-container, #col-container-2 {max-width: 510px; margin-left: auto; margin-right: auto;}
|
| 52 |
-
a {text-decoration-line: underline; font-weight: 600;}
|
| 53 |
-
div#record_btn > .mt-6 {
|
| 54 |
-
margin-top: 0!important;
|
| 55 |
-
}
|
| 56 |
-
div#record_btn > .mt-6 button {
|
| 57 |
-
width: 100%;
|
| 58 |
-
height: 40px;
|
| 59 |
-
}
|
| 60 |
-
.footer {
|
| 61 |
-
margin-bottom: 45px;
|
| 62 |
-
margin-top: 10px;
|
| 63 |
-
text-align: center;
|
| 64 |
-
border-bottom: 1px solid #e5e5e5;
|
| 65 |
-
}
|
| 66 |
-
.footer>p {
|
| 67 |
-
font-size: .8rem;
|
| 68 |
-
display: inline-block;
|
| 69 |
-
padding: 0 10px;
|
| 70 |
-
transform: translateY(10px);
|
| 71 |
-
background: white;
|
| 72 |
-
}
|
| 73 |
-
.dark .footer {
|
| 74 |
-
border-color: #303030;
|
| 75 |
-
}
|
| 76 |
-
.dark .footer>p {
|
| 77 |
-
background: #0b0f19;
|
| 78 |
-
}
|
| 79 |
-
.animate-spin {
|
| 80 |
-
animation: spin 1s linear infinite;
|
| 81 |
-
}
|
| 82 |
-
@keyframes spin {
|
| 83 |
-
from {
|
| 84 |
-
transform: rotate(0deg);
|
| 85 |
-
}
|
| 86 |
-
to {
|
| 87 |
-
transform: rotate(360deg);
|
| 88 |
-
}
|
| 89 |
-
}
|
| 90 |
-
#share-btn-container {
|
| 91 |
-
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
| 92 |
-
}
|
| 93 |
-
#share-btn {
|
| 94 |
-
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
|
| 95 |
-
}
|
| 96 |
-
#share-btn * {
|
| 97 |
-
all: unset;
|
| 98 |
-
}
|
| 99 |
-
#share-btn-container div:nth-child(-n+2){
|
| 100 |
-
width: auto !important;
|
| 101 |
-
min-height: 0px !important;
|
| 102 |
-
}
|
| 103 |
-
#share-btn-container .wrap {
|
| 104 |
-
display: none !important;
|
| 105 |
-
}
|
| 106 |
-
'''
|
| 107 |
-
|
| 108 |
with gr.Blocks(css="style.css") as demo:
|
| 109 |
-
|
| 110 |
with gr.Column(elem_id="col-container"):
|
| 111 |
-
|
| 112 |
gr.HTML(title)
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
with gr.Column(elem_id="col-container-2"):
|
| 121 |
-
|
| 122 |
-
spectrogram_output = gr.Image(label="Spectrogram Image Result", elem_id="img-out")
|
| 123 |
-
sound_output = gr.Audio(type='filepath', label="Generated Audio", elem_id="music-out")
|
| 124 |
-
|
| 125 |
send_btn.click(predict, inputs=[prompt_input, duration_input], outputs=[spectrogram_output, sound_output])
|
| 126 |
|
| 127 |
demo.queue(max_size=250).launch(debug=True, ssr_mode=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
|
|
|
|
|
|
| 3 |
from spectro import wav_bytes_from_spectrogram_image
|
|
|
|
| 4 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 5 |
|
| 6 |
device = "cpu"
|
| 7 |
MODEL_ID = "Hyeon2/riffusion-musiccaps"
|
| 8 |
pipe = StableDiffusionPipeline.from_pretrained(MODEL_ID)
|
| 9 |
pipe = pipe.to(device)
|
| 10 |
|
| 11 |
+
def predict(prompt):
|
| 12 |
+
spec = pipe(prompt).images[0].convert("L")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
print(spec)
|
| 14 |
wav = wav_bytes_from_spectrogram_image(spec)
|
| 15 |
with open("output.wav", "wb") as f:
|
|
|
|
| 38 |
</div>
|
| 39 |
"""
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
with gr.Blocks(css="style.css") as demo:
|
|
|
|
| 42 |
with gr.Column(elem_id="col-container"):
|
|
|
|
| 43 |
gr.HTML(title)
|
| 44 |
+
with gr.Row():
|
| 45 |
+
with gr.Column():
|
| 46 |
+
prompt_input = gr.Textbox(placeholder="A LoFi beat", label="Musical prompt", elem_id="prompt-in")
|
| 47 |
+
send_btn = gr.Button(value="Get a new spectrogram!", elem_id="submit-btn")
|
| 48 |
+
with gr.Column(elem_id="col-container-2"):
|
| 49 |
+
spectrogram_output = gr.Image(label="Spectrogram Image Result", elem_id="img-out")
|
| 50 |
+
sound_output = gr.Audio(type='filepath', label="Generated Audio", elem_id="music-out")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
send_btn.click(predict, inputs=[prompt_input, duration_input], outputs=[spectrogram_output, sound_output])
|
| 52 |
|
| 53 |
demo.queue(max_size=250).launch(debug=True, ssr_mode=False)
|