Spaces:
Sleeping
Sleeping
fix errors when users change the parameters while inversion is ongoing
Browse files
app.py
CHANGED
@@ -209,9 +209,23 @@ change <code style="display:inline; background-color: lightgrey; ">duration = mi
|
|
209 |
"""
|
210 |
|
211 |
with gr.Blocks(css='style.css', delete_cache=(3600, 3600)) as demo:
|
212 |
-
def reset_do_inversion():
|
213 |
-
do_inversion = gr.State(value=True)
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
gr.HTML(intro)
|
216 |
# wts = gr.State()
|
217 |
# zs = gr.State()
|
@@ -222,6 +236,7 @@ with gr.Blocks(css='style.css', delete_cache=(3600, 3600)) as demo:
|
|
222 |
# ldm_stable = load_model("cvssp/audioldm2-music", device, 200)
|
223 |
# ldm_stable = gr.State(value=ldm_stable)
|
224 |
do_inversion = gr.State(value=True) # To save some runtime when editing the same thing over and over
|
|
|
225 |
|
226 |
with gr.Group():
|
227 |
gr.Markdown("💡 **note**: input longer than **30 sec** is automatically trimmed (for unlimited input, see the Help section below)")
|
@@ -276,6 +291,7 @@ with gr.Blocks(css='style.css', delete_cache=(3600, 3600)) as demo:
|
|
276 |
fn=randomize_seed_fn,
|
277 |
inputs=[seed, randomize_seed],
|
278 |
outputs=[seed], queue=False).then(
|
|
|
279 |
fn=edit,
|
280 |
inputs=[cache_dir,
|
281 |
input_audio,
|
@@ -295,16 +311,18 @@ with gr.Blocks(css='style.css', delete_cache=(3600, 3600)) as demo:
|
|
295 |
],
|
296 |
outputs=[output_audio, wtszs,
|
297 |
saved_inv_model, do_inversion] # , current_loaded_model, ldm_stable],
|
298 |
-
).then(
|
|
|
299 |
inputs=wtszs)
|
300 |
|
301 |
# demo.move_resource_to_block_cache(wtszs.value)
|
302 |
|
303 |
# If sources changed we have to rerun inversion
|
304 |
-
input_audio.change(fn=reset_do_inversion, outputs=[do_inversion])
|
305 |
-
src_prompt.change(fn=reset_do_inversion, outputs=[do_inversion])
|
306 |
-
model_id.change(fn=reset_do_inversion, outputs=[do_inversion])
|
307 |
-
|
|
|
308 |
|
309 |
gr.Examples(
|
310 |
label="Examples",
|
|
|
209 |
"""
|
210 |
|
211 |
with gr.Blocks(css='style.css', delete_cache=(3600, 3600)) as demo:
|
212 |
+
def reset_do_inversion(do_inversion_user, do_inversion):
|
213 |
+
# do_inversion = gr.State(value=True)
|
214 |
+
do_inversion = True
|
215 |
+
do_inversion_user = True
|
216 |
+
return do_inversion_user, do_inversion
|
217 |
+
|
218 |
+
# handle the case where the user clicked the button but the inversion was not done
|
219 |
+
def clear_do_inversion_user(do_inversion_user):
|
220 |
+
do_inversion_user = False
|
221 |
+
return do_inversion_user
|
222 |
+
def post_match_do_inversion(do_inversion_user, do_inversion):
|
223 |
+
if do_inversion_user:
|
224 |
+
do_inversion = True
|
225 |
+
do_inversion_user = False
|
226 |
+
return do_inversion_user, do_inversion
|
227 |
+
|
228 |
+
|
229 |
gr.HTML(intro)
|
230 |
# wts = gr.State()
|
231 |
# zs = gr.State()
|
|
|
236 |
# ldm_stable = load_model("cvssp/audioldm2-music", device, 200)
|
237 |
# ldm_stable = gr.State(value=ldm_stable)
|
238 |
do_inversion = gr.State(value=True) # To save some runtime when editing the same thing over and over
|
239 |
+
do_inversion_user = gr.State(value=False)
|
240 |
|
241 |
with gr.Group():
|
242 |
gr.Markdown("💡 **note**: input longer than **30 sec** is automatically trimmed (for unlimited input, see the Help section below)")
|
|
|
291 |
fn=randomize_seed_fn,
|
292 |
inputs=[seed, randomize_seed],
|
293 |
outputs=[seed], queue=False).then(
|
294 |
+
fn=clear_do_inversion_user, inputs=[do_inversion_user], outputs=[do_inversion_user]).then(
|
295 |
fn=edit,
|
296 |
inputs=[cache_dir,
|
297 |
input_audio,
|
|
|
311 |
],
|
312 |
outputs=[output_audio, wtszs,
|
313 |
saved_inv_model, do_inversion] # , current_loaded_model, ldm_stable],
|
314 |
+
).then(post_match_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion]
|
315 |
+
).then(lambda x: (demo.temp_file_sets.append(set([str(gr.utils.abspath(x))])) if type(x) is str else None),
|
316 |
inputs=wtszs)
|
317 |
|
318 |
# demo.move_resource_to_block_cache(wtszs.value)
|
319 |
|
320 |
# If sources changed we have to rerun inversion
|
321 |
+
input_audio.change(fn=reset_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion])
|
322 |
+
src_prompt.change(fn=reset_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion])
|
323 |
+
model_id.change(fn=reset_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion])
|
324 |
+
cfg_scale_src.change(fn=reset_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion])
|
325 |
+
steps.change(fn=reset_do_inversion, inputs=[do_inversion_user, do_inversion], outputs=[do_inversion_user, do_inversion])
|
326 |
|
327 |
gr.Examples(
|
328 |
label="Examples",
|