Update app.py
Browse files
app.py
CHANGED
@@ -47,263 +47,15 @@ def text2audio(text, duration, guidance_scale, random_seed, n_candidates, model_
|
|
47 |
waveform = waveform[0]
|
48 |
return waveform
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
css = """
|
62 |
-
a {
|
63 |
-
color: inherit;
|
64 |
-
text-decoration: underline;
|
65 |
-
}
|
66 |
-
.gradio-container {
|
67 |
-
font-family: 'IBM Plex Sans', sans-serif;
|
68 |
-
}
|
69 |
-
.gr-button {
|
70 |
-
color: white;
|
71 |
-
border-color: #000000;
|
72 |
-
background: #000000;
|
73 |
-
}
|
74 |
-
input[type='range'] {
|
75 |
-
accent-color: #000000;
|
76 |
-
}
|
77 |
-
.dark input[type='range'] {
|
78 |
-
accent-color: #dfdfdf;
|
79 |
-
}
|
80 |
-
.container {
|
81 |
-
max-width: 730px;
|
82 |
-
margin: auto;
|
83 |
-
padding-top: 1.5rem;
|
84 |
-
}
|
85 |
-
#gallery {
|
86 |
-
min-height: 22rem;
|
87 |
-
margin-bottom: 15px;
|
88 |
-
margin-left: auto;
|
89 |
-
margin-right: auto;
|
90 |
-
border-bottom-right-radius: .5rem !important;
|
91 |
-
border-bottom-left-radius: .5rem !important;
|
92 |
-
}
|
93 |
-
#gallery>div>.h-full {
|
94 |
-
min-height: 20rem;
|
95 |
-
}
|
96 |
-
.details:hover {
|
97 |
-
text-decoration: underline;
|
98 |
-
}
|
99 |
-
.gr-button {
|
100 |
-
white-space: nowrap;
|
101 |
-
}
|
102 |
-
.gr-button:focus {
|
103 |
-
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
104 |
-
outline: none;
|
105 |
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
106 |
-
--tw-border-opacity: 1;
|
107 |
-
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
108 |
-
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
109 |
-
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
110 |
-
--tw-ring-opacity: .5;
|
111 |
-
}
|
112 |
-
#advanced-btn {
|
113 |
-
font-size: .7rem !important;
|
114 |
-
line-height: 19px;
|
115 |
-
margin-top: 12px;
|
116 |
-
margin-bottom: 12px;
|
117 |
-
padding: 2px 8px;
|
118 |
-
border-radius: 14px !important;
|
119 |
-
}
|
120 |
-
#advanced-options {
|
121 |
-
margin-bottom: 20px;
|
122 |
-
}
|
123 |
-
.footer {
|
124 |
-
margin-bottom: 45px;
|
125 |
-
margin-top: 35px;
|
126 |
-
text-align: center;
|
127 |
-
border-bottom: 1px solid #e5e5e5;
|
128 |
-
}
|
129 |
-
.footer>p {
|
130 |
-
font-size: .8rem;
|
131 |
-
display: inline-block;
|
132 |
-
padding: 0 10px;
|
133 |
-
transform: translateY(10px);
|
134 |
-
background: white;
|
135 |
-
}
|
136 |
-
.dark .footer {
|
137 |
-
border-color: #303030;
|
138 |
-
}
|
139 |
-
.dark .footer>p {
|
140 |
-
background: #0b0f19;
|
141 |
-
}
|
142 |
-
.acknowledgments h4{
|
143 |
-
margin: 1.25em 0 .25em 0;
|
144 |
-
font-weight: bold;
|
145 |
-
font-size: 115%;
|
146 |
-
}
|
147 |
-
#container-advanced-btns{
|
148 |
-
display: flex;
|
149 |
-
flex-wrap: wrap;
|
150 |
-
justify-content: space-between;
|
151 |
-
align-items: center;
|
152 |
-
}
|
153 |
-
.animate-spin {
|
154 |
-
animation: spin 1s linear infinite;
|
155 |
-
}
|
156 |
-
@keyframes spin {
|
157 |
-
from {
|
158 |
-
transform: rotate(0deg);
|
159 |
-
}
|
160 |
-
to {
|
161 |
-
transform: rotate(360deg);
|
162 |
-
}
|
163 |
-
}
|
164 |
-
#share-btn-container {
|
165 |
-
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;
|
166 |
-
margin-top: 10px;
|
167 |
-
margin-left: auto;
|
168 |
-
}
|
169 |
-
#share-btn {
|
170 |
-
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;
|
171 |
-
}
|
172 |
-
#share-btn * {
|
173 |
-
all: unset;
|
174 |
-
}
|
175 |
-
#share-btn-container div:nth-child(-n+2){
|
176 |
-
width: auto !important;
|
177 |
-
min-height: 0px !important;
|
178 |
-
}
|
179 |
-
#share-btn-container .wrap {
|
180 |
-
display: none !important;
|
181 |
-
}
|
182 |
-
.gr-form{
|
183 |
-
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
184 |
-
}
|
185 |
-
#prompt-container{
|
186 |
-
gap: 0;
|
187 |
-
}
|
188 |
-
#generated_id{
|
189 |
-
min-height: 700px
|
190 |
-
}
|
191 |
-
#setting_id{
|
192 |
-
margin-bottom: 12px;
|
193 |
-
text-align: center;
|
194 |
-
font-weight: 900;
|
195 |
-
}
|
196 |
-
"""
|
197 |
-
iface = gr.Blocks(css=css)
|
198 |
-
|
199 |
-
with iface:
|
200 |
-
gr.HTML(
|
201 |
-
"""
|
202 |
-
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
203 |
-
<div
|
204 |
-
style="
|
205 |
-
display: inline-flex;
|
206 |
-
align-items: center;
|
207 |
-
gap: 0.8rem;
|
208 |
-
font-size: 1.75rem;
|
209 |
-
"
|
210 |
-
>
|
211 |
-
<h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
|
212 |
-
AudioLDM: Text-to-Audio Generation with Latent Diffusion Models
|
213 |
-
</h1>
|
214 |
-
</div>
|
215 |
-
<p style="margin-bottom: 10px; font-size: 94%">
|
216 |
-
<a href="https://arxiv.org/abs/2301.12503">[Paper]</a> <a href="https://audioldm.github.io/">[Project page]</a>
|
217 |
-
</p>
|
218 |
-
</div>
|
219 |
-
"""
|
220 |
-
)
|
221 |
-
gr.HTML("""
|
222 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
223 |
-
AudioLDM: Text-to-Audio Generation with Latent Diffusion Models
|
224 |
-
</h1>
|
225 |
-
<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.
|
226 |
-
<br/>
|
227 |
-
<a href="https://huggingface.co/spaces/haoheliu/audioldm-text-to-audio-generation?duplicate=true">
|
228 |
-
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
229 |
-
<p/>
|
230 |
-
""")
|
231 |
-
with gr.Group():
|
232 |
-
with gr.Box():
|
233 |
-
############# Input
|
234 |
-
textbox = gr.Textbox(value="A hammer is hitting a wooden surface", max_lines=1, label="Input your text here. Your text is important for the audio quality. Please ensure it is descriptive by using more adjectives.", elem_id="prompt-in")
|
235 |
-
|
236 |
-
with gr.Accordion("Click to modify detailed configurations", open=False):
|
237 |
-
seed = gr.Number(value=45, label="Change this value (any integer number) will lead to a different generation result.")
|
238 |
-
duration = gr.Slider(2.5, 10, value=5, step=2.5, label="Duration (seconds)")
|
239 |
-
guidance_scale = gr.Slider(0, 4, value=2.5, step=0.5, label="Guidance scale (Large => better quality and relavancy to text; Small => better diversity)")
|
240 |
-
n_candidates = gr.Slider(1, 3, value=3, step=1, label="Automatic quality control. This number control the number of candidates (e.g., generate three audios and choose the best to show you). A Larger value usually lead to better quality with heavier computation")
|
241 |
-
# model_name = gr.Dropdown(
|
242 |
-
# ["audioldm-m-text-ft", "audioldm-s-text-ft", "audioldm-m-full","audioldm-s-full-v2", "audioldm-s-full", "audioldm-l-full"], value="audioldm-m-full", label="Choose the model to use. audioldm-m-text-ft and audioldm-s-text-ft are recommanded. -s- means small, -m- means medium and -l- means large",
|
243 |
-
# )
|
244 |
-
############# Output
|
245 |
-
# outputs=gr.Audio(label="Output", type="numpy")
|
246 |
-
outputs=gr.Video(label="Output", elem_id="output-video")
|
247 |
-
|
248 |
-
# with gr.Group(elem_id="container-advanced-btns"):
|
249 |
-
# # advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
250 |
-
# with gr.Group(elem_id="share-btn-container"):
|
251 |
-
# community_icon = gr.HTML(community_icon_html, visible=False)
|
252 |
-
# loading_icon = gr.HTML(loading_icon_html, visible=False)
|
253 |
-
# share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
254 |
-
# outputs=[gr.Audio(label="Output", type="numpy"), gr.Audio(label="Output", type="numpy")]
|
255 |
-
btn = gr.Button("Submit").style(full_width=True)
|
256 |
-
|
257 |
-
with gr.Group(elem_id="share-btn-container", visible=False):
|
258 |
-
community_icon = gr.HTML(community_icon_html)
|
259 |
-
loading_icon = gr.HTML(loading_icon_html)
|
260 |
-
share_button = gr.Button("Share to community", elem_id="share-btn")
|
261 |
-
|
262 |
-
# btn.click(text2audio, inputs=[
|
263 |
-
# textbox, duration, guidance_scale, seed, n_candidates, model_name], outputs=[outputs])
|
264 |
-
btn.click(text2audio, inputs=[
|
265 |
-
textbox, duration, guidance_scale, seed, n_candidates], outputs=[outputs])
|
266 |
-
|
267 |
-
share_button.click(None, [], [], _js=share_js)
|
268 |
-
gr.HTML('''
|
269 |
-
<div class="footer" style="text-align: center; max-width: 700px; margin: 0 auto;">
|
270 |
-
<p>Follow the latest update of AudioLDM on our<a href="https://github.com/haoheliu/AudioLDM" style="text-decoration: underline;" target="_blank"> Github repo</a>
|
271 |
-
</p>
|
272 |
-
<br>
|
273 |
-
<p>Model by <a href="https://twitter.com/LiuHaohe" style="text-decoration: underline;" target="_blank">Haohe Liu</a></p>
|
274 |
-
<br>
|
275 |
-
</div>
|
276 |
-
''')
|
277 |
-
gr.Examples([
|
278 |
-
["A hammer is hitting a wooden surface", 5, 2.5, 45, 3, "audioldm-m-full"],
|
279 |
-
["Peaceful and calming ambient music with singing bowl and other instruments.", 5, 2.5, 45, 3, "audioldm-m-full"],
|
280 |
-
["A man is speaking in a small room.", 5, 2.5, 45, 3, "audioldm-m-full"],
|
281 |
-
["A female is speaking followed by footstep sound", 5, 2.5, 45, 3, "audioldm-m-full"],
|
282 |
-
["Wooden table tapping sound followed by water pouring sound.", 5, 2.5, 45, 3, "audioldm-m-full"],
|
283 |
-
],
|
284 |
-
fn=text2audio,
|
285 |
-
# inputs=[textbox, duration, guidance_scale, seed, n_candidates, model_name],
|
286 |
-
inputs=[textbox, duration, guidance_scale, seed, n_candidates],
|
287 |
-
outputs=[outputs],
|
288 |
-
cache_examples=True,
|
289 |
-
)
|
290 |
-
gr.HTML('''
|
291 |
-
<div class="acknowledgements">
|
292 |
-
<p>Essential Tricks for Enhancing the Quality of Your Generated Audio</p>
|
293 |
-
<p>1. Try to use more adjectives to describe your sound. For example: "A man is speaking clearly and slowly in a large room" is better than "A man is speaking". This can make sure AudioLDM understands what you want.</p>
|
294 |
-
<p>2. Try to use different random seeds, which can affect the generation quality significantly sometimes.</p>
|
295 |
-
<p>3. It's better to use general terms like 'man' or 'woman' instead of specific names for individuals or abstract objects that humans may not be familiar with, such as 'mummy'.</p>
|
296 |
-
</div>
|
297 |
-
''')
|
298 |
-
with gr.Accordion("Additional information", open=False):
|
299 |
-
gr.HTML(
|
300 |
-
"""
|
301 |
-
<div class="acknowledgments">
|
302 |
-
<p> We build the model with data from <a href="http://research.google.com/audioset/">AudioSet</a>, <a href="https://freesound.org/">Freesound</a> and <a href="https://sound-effects.bbcrewind.co.uk/">BBC Sound Effect library</a>. We share this demo based on the <a href="https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/375954/Research.pdf">UK copyright exception</a> of data for academic research. </p>
|
303 |
-
</div>
|
304 |
-
"""
|
305 |
-
)
|
306 |
-
# <p>This demo is strictly for research demo purpose only. For commercial use please <a href="[email protected]">contact us</a>.</p>
|
307 |
-
|
308 |
-
iface.queue(max_size=10).launch(debug=True)
|
309 |
# iface.launch(debug=True, share=True)
|
|
|
47 |
waveform = waveform[0]
|
48 |
return waveform
|
49 |
|
50 |
+
iface = gr.Interface(fn=text2audio, inputs=[
|
51 |
+
gr.Textbox(value="A man is speaking in a huge room", max_lines=1),
|
52 |
+
gr.Slider(2.5, 10, value=5, step=2.5),
|
53 |
+
gr.Slider(0, 5, value=2.5, step=0.5),
|
54 |
+
gr.Number(value=42)
|
55 |
+
], outputs=[gr.Audio(label="Output", type="numpy"), gr.Audio(label="Output", type="numpy")],
|
56 |
+
allow_flagging="never"
|
57 |
+
)
|
58 |
+
iface.launch(share=True)
|
59 |
+
|
60 |
+
#iface.queue(max_size=10).launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# iface.launch(debug=True, share=True)
|