Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,13 +17,98 @@ def predict(prompt):
|
|
| 17 |
f.write(wav[0].getbuffer())
|
| 18 |
return spec, 'output.wav'
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
f.write(wav[0].getbuffer())
|
| 18 |
return spec, 'output.wav'
|
| 19 |
|
| 20 |
+
title = """
|
| 21 |
+
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
| 22 |
+
<div
|
| 23 |
+
style="
|
| 24 |
+
display: inline-flex;
|
| 25 |
+
align-items: center;
|
| 26 |
+
gap: 0.8rem;
|
| 27 |
+
font-size: 1.75rem;
|
| 28 |
+
margin-bottom: 10px;
|
| 29 |
+
"
|
| 30 |
+
>
|
| 31 |
+
<h1 style="font-weight: 600; margin-bottom: 7px;">
|
| 32 |
+
Riffusion - Stable diffusion for real-time music generation
|
| 33 |
+
</h1>
|
| 34 |
+
</div>
|
| 35 |
+
<p style="margin-bottom: 10px;font-size: 94%;font-weight: 100;line-height: 1.5em;">
|
| 36 |
+
Describe a musical prompt, generate music by getting a Riffusion spectrogram and its corresponding sound.
|
| 37 |
+
|
| 38 |
+
<p style="font-size: 94%">
|
| 39 |
+
Do you need faster results ? You can skip the queue by duplicating this space:
|
| 40 |
+
<span style="display: flex;align-items: center;justify-content: center;height: 30px;">
|
| 41 |
+
<a href="https://huggingface.co/fffiloni/spectrogram-to-music?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
|
| 42 |
+
</span>
|
| 43 |
+
</p>
|
| 44 |
+
</div>
|
| 45 |
"""
|
| 46 |
+
|
| 47 |
+
article = """
|
| 48 |
+
<p style="font-size: 0.8em;line-height: 1.2em;">
|
| 49 |
+
About the model: Riffusion is a latent text-to-image diffusion model capable of generating spectrogram images given any text input. These spectrograms can be converted into audio clips.
|
| 50 |
+
<br />The Riffusion model was created by fine-tuning the Stable-Diffusion-v1-5 checkpoint.
|
| 51 |
+
<br />The model is intended for research purposes only. Possible research areas and tasks include
|
| 52 |
+
generation of artworks, audio, and use in creative processes, applications in educational or creative tools, research on generative models.
|
| 53 |
+
|
| 54 |
+
</p>
|
| 55 |
+
<div class="footer">
|
| 56 |
+
<p>
|
| 57 |
+
<a href="https://huggingface.co/riffusion/riffusion-model-v1" target="_blank">Riffusion model</a> by Seth Forsgren and Hayk Martiros -
|
| 58 |
+
Gradio Demo by 🤗 <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
|
| 59 |
+
</p>
|
| 60 |
+
</div>
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
css = '''
|
| 64 |
+
#col-container, #col-container-2 {max-width: 510px; margin-left: auto; margin-right: auto;}
|
| 65 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
| 66 |
+
div#record_btn > .mt-6 {
|
| 67 |
+
margin-top: 0!important;
|
| 68 |
+
}
|
| 69 |
+
div#record_btn > .mt-6 button {
|
| 70 |
+
width: 100%;
|
| 71 |
+
height: 40px;
|
| 72 |
+
}
|
| 73 |
+
.footer {
|
| 74 |
+
margin-bottom: 45px;
|
| 75 |
+
margin-top: 10px;
|
| 76 |
+
text-align: center;
|
| 77 |
+
border-bottom: 1px solid #e5e5e5;
|
| 78 |
+
}
|
| 79 |
+
.footer>p {
|
| 80 |
+
font-size: .8rem;
|
| 81 |
+
display: inline-block;
|
| 82 |
+
padding: 0 10px;
|
| 83 |
+
transform: translateY(10px);
|
| 84 |
+
background: white;
|
| 85 |
+
}
|
| 86 |
+
.dark .footer {
|
| 87 |
+
border-color: #303030;
|
| 88 |
+
}
|
| 89 |
+
.dark .footer>p {
|
| 90 |
+
background: #0b0f19;
|
| 91 |
+
}
|
| 92 |
+
'''
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
with gr.Blocks(css=css) as demo:
|
| 97 |
+
|
| 98 |
+
with gr.Column(elem_id="col-container"):
|
| 99 |
+
|
| 100 |
+
gr.HTML(title)
|
| 101 |
+
|
| 102 |
+
prompt_input = gr.Textbox(placeholder="a cat diva singing in a New York jazz club")
|
| 103 |
+
|
| 104 |
+
send_btn = gr.Button("Get a new spectrogram ! ")
|
| 105 |
+
|
| 106 |
+
with gr.Column(elem_id="col-container-2"):
|
| 107 |
+
spectrogram_output = gr.Image(label="spectrogram image result")
|
| 108 |
+
sound_output = gr.Audio(type='filepath', label="spectrogram sound")
|
| 109 |
+
|
| 110 |
+
gr.HTML(article)
|
| 111 |
+
|
| 112 |
+
send_btn.click(chat_hf, inputs=[prompt_input], outputs=[spectrogram_output, sound_output])
|
| 113 |
+
|
| 114 |
+
demo.queue(max_size=250).launch(debug=True)
|