Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,7 @@ def invert(x0, prompt_src, num_diffusion_steps, cfg_scale_src): # , ldm_stable)
|
|
33 |
return zs, wts
|
34 |
|
35 |
|
|
|
36 |
def sample(zs, wts, steps, prompt_tar, tstart, cfg_scale_tar): # , ldm_stable):
|
37 |
# reverse process (via Zs and wT)
|
38 |
tstart = torch.tensor(tstart, dtype=torch.int)
|
@@ -57,6 +58,14 @@ def sample(zs, wts, steps, prompt_tar, tstart, cfg_scale_tar): # , ldm_stable):
|
|
57 |
|
58 |
return f.name
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
def edit(input_audio,
|
62 |
model_id: str,
|
@@ -92,6 +101,9 @@ def edit(input_audio,
|
|
92 |
zs = gr.State(value=zs_tensor)
|
93 |
saved_inv_model = model_id
|
94 |
do_inversion = False
|
|
|
|
|
|
|
95 |
|
96 |
output = sample(zs.value, wts.value, steps, prompt_tar=target_prompt, tstart=t_start,
|
97 |
cfg_scale_tar=cfg_scale_tar)
|
@@ -221,21 +233,14 @@ with gr.Blocks(css='style.css') as demo:
|
|
221 |
label="Source Guidance Scale", interactive=True, scale=1)
|
222 |
cfg_scale_tar = gr.Number(value=12, minimum=0.5, maximum=25, precision=None,
|
223 |
label="Target Guidance Scale", interactive=True, scale=1)
|
224 |
-
steps = gr.Number(value=200,
|
225 |
label="Num Diffusion Steps", interactive=True, scale=1)
|
226 |
with gr.Row():
|
227 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
228 |
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
229 |
length = gr.Number(label="Length", interactive=False, visible=False)
|
230 |
|
231 |
-
|
232 |
-
t_start.maximum = int(160/200 * steps)
|
233 |
-
t_start.minimum = int(30/200 * steps)
|
234 |
-
if t_start.value > t_start.maximum:
|
235 |
-
t_start.value = t_start.maximum
|
236 |
-
if t_start.value < t_start.minimum:
|
237 |
-
t_start.value = t_start.minimum
|
238 |
-
return t_start
|
239 |
|
240 |
submit.click(
|
241 |
fn=randomize_seed_fn,
|
@@ -262,7 +267,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
262 |
input_audio.change(fn=reset_do_inversion, outputs=[do_inversion])
|
263 |
src_prompt.change(fn=reset_do_inversion, outputs=[do_inversion])
|
264 |
model_id.change(fn=reset_do_inversion, outputs=[do_inversion])
|
265 |
-
steps.change(fn=change_tstart_range, inputs=[steps], outputs=[t_start])
|
266 |
|
267 |
gr.Examples(
|
268 |
label="Examples",
|
|
|
33 |
return zs, wts
|
34 |
|
35 |
|
36 |
+
|
37 |
def sample(zs, wts, steps, prompt_tar, tstart, cfg_scale_tar): # , ldm_stable):
|
38 |
# reverse process (via Zs and wT)
|
39 |
tstart = torch.tensor(tstart, dtype=torch.int)
|
|
|
58 |
|
59 |
return f.name
|
60 |
|
61 |
+
def change_tstart_range(t_start, steps):
|
62 |
+
maximum = int(0.8 * steps)
|
63 |
+
minimum = int(0.15 * steps)
|
64 |
+
if t_start > maximum:
|
65 |
+
t_start = maximum
|
66 |
+
elif t_start < minimum:
|
67 |
+
t_start = minimum
|
68 |
+
return t_start
|
69 |
|
70 |
def edit(input_audio,
|
71 |
model_id: str,
|
|
|
101 |
zs = gr.State(value=zs_tensor)
|
102 |
saved_inv_model = model_id
|
103 |
do_inversion = False
|
104 |
+
|
105 |
+
# make sure t_start is in the right limit
|
106 |
+
t_start = change_tstart_range(t_start, steps)
|
107 |
|
108 |
output = sample(zs.value, wts.value, steps, prompt_tar=target_prompt, tstart=t_start,
|
109 |
cfg_scale_tar=cfg_scale_tar)
|
|
|
233 |
label="Source Guidance Scale", interactive=True, scale=1)
|
234 |
cfg_scale_tar = gr.Number(value=12, minimum=0.5, maximum=25, precision=None,
|
235 |
label="Target Guidance Scale", interactive=True, scale=1)
|
236 |
+
steps = gr.Number(value=200, step=1, minimum=20, maximum=1000,
|
237 |
label="Num Diffusion Steps", interactive=True, scale=1)
|
238 |
with gr.Row():
|
239 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
240 |
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
241 |
length = gr.Number(label="Length", interactive=False, visible=False)
|
242 |
|
243 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
submit.click(
|
246 |
fn=randomize_seed_fn,
|
|
|
267 |
input_audio.change(fn=reset_do_inversion, outputs=[do_inversion])
|
268 |
src_prompt.change(fn=reset_do_inversion, outputs=[do_inversion])
|
269 |
model_id.change(fn=reset_do_inversion, outputs=[do_inversion])
|
270 |
+
# steps.change(fn=change_tstart_range, inputs=[steps], outputs=[t_start])
|
271 |
|
272 |
gr.Examples(
|
273 |
label="Examples",
|