Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,7 +76,7 @@ def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guida
|
|
| 76 |
return gr.update(label=comma_concepts_x, interactive=True, value=0), x_concept_1, x_concept_2, avg_diff_x
|
| 77 |
|
| 78 |
@spaces.GPU
|
| 79 |
-
def update_scales(x,prompt,seed, steps, guidance_scale,
|
| 80 |
avg_diff_x,
|
| 81 |
img2img_type = None, img = None,
|
| 82 |
controlnet_scale= None, ip_adapter_scale=None,):
|
|
@@ -85,7 +85,6 @@ def update_scales(x,prompt,seed, steps, guidance_scale,
|
|
| 85 |
|
| 86 |
# for spectrum generation
|
| 87 |
images = []
|
| 88 |
-
img_steps=5
|
| 89 |
|
| 90 |
high_scale = x
|
| 91 |
low_scale = -1 * x
|
|
@@ -96,7 +95,7 @@ def update_scales(x,prompt,seed, steps, guidance_scale,
|
|
| 96 |
elif img2img_type=="ip adapter" and img is not None:
|
| 97 |
image = clip_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=x,seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
| 98 |
else:
|
| 99 |
-
for i in range(
|
| 100 |
cur_scale = low_scale + (high_scale - low_scale) * i / (steps - 1)
|
| 101 |
image = clip_slider.generate(prompt,
|
| 102 |
#guidance_scale=guidance_scale,
|
|
@@ -180,10 +179,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 180 |
slider_x = gr.Dropdown(label="Slider concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 181 |
#slider_y = gr.Dropdown(label="Slider Y concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 182 |
prompt = gr.Textbox(label="Prompt")
|
|
|
|
| 183 |
submit = gr.Button("find directions")
|
| 184 |
with gr.Column():
|
| 185 |
with gr.Group(elem_id="group"):
|
| 186 |
-
x = gr.Slider(minimum=0, value=1.25, step=0.1, maximum=2.5, elem_id="x", interactive=False)
|
| 187 |
#y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
|
| 188 |
output_image = gr.Image(elem_id="image_out")
|
| 189 |
image_seq = gr.Image()
|
|
@@ -193,6 +192,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 193 |
with gr.Accordion(label="advanced options", open=False):
|
| 194 |
iterations = gr.Slider(label = "num iterations", minimum=0, value=200, maximum=400)
|
| 195 |
steps = gr.Slider(label = "num inference steps", minimum=1, value=4, maximum=10)
|
|
|
|
| 196 |
guidance_scale = gr.Slider(
|
| 197 |
label="Guidance scale",
|
| 198 |
minimum=0.1,
|
|
@@ -259,11 +259,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 259 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 260 |
submit.click(fn=generate,
|
| 261 |
inputs=[slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
| 262 |
-
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image]).then(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image, image_seq])
|
| 263 |
|
| 264 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 265 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 266 |
-
x.release(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image, image_seq], trigger_mode='always_last')
|
| 267 |
# generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
|
| 268 |
# submit_a.click(fn=generate,
|
| 269 |
# inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],
|
|
|
|
| 76 |
return gr.update(label=comma_concepts_x, interactive=True, value=0), x_concept_1, x_concept_2, avg_diff_x
|
| 77 |
|
| 78 |
@spaces.GPU
|
| 79 |
+
def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
|
| 80 |
avg_diff_x,
|
| 81 |
img2img_type = None, img = None,
|
| 82 |
controlnet_scale= None, ip_adapter_scale=None,):
|
|
|
|
| 85 |
|
| 86 |
# for spectrum generation
|
| 87 |
images = []
|
|
|
|
| 88 |
|
| 89 |
high_scale = x
|
| 90 |
low_scale = -1 * x
|
|
|
|
| 95 |
elif img2img_type=="ip adapter" and img is not None:
|
| 96 |
image = clip_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=x,seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
| 97 |
else:
|
| 98 |
+
for i in range(interm_steps):
|
| 99 |
cur_scale = low_scale + (high_scale - low_scale) * i / (steps - 1)
|
| 100 |
image = clip_slider.generate(prompt,
|
| 101 |
#guidance_scale=guidance_scale,
|
|
|
|
| 179 |
slider_x = gr.Dropdown(label="Slider concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 180 |
#slider_y = gr.Dropdown(label="Slider Y concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 181 |
prompt = gr.Textbox(label="Prompt")
|
| 182 |
+
x = gr.Slider(minimum=0, value=1.25, step=0.1, maximum=2.5, elem_id="x", interactive=False, info="the strength to scale in each direction")
|
| 183 |
submit = gr.Button("find directions")
|
| 184 |
with gr.Column():
|
| 185 |
with gr.Group(elem_id="group"):
|
|
|
|
| 186 |
#y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
|
| 187 |
output_image = gr.Image(elem_id="image_out")
|
| 188 |
image_seq = gr.Image()
|
|
|
|
| 192 |
with gr.Accordion(label="advanced options", open=False):
|
| 193 |
iterations = gr.Slider(label = "num iterations", minimum=0, value=200, maximum=400)
|
| 194 |
steps = gr.Slider(label = "num inference steps", minimum=1, value=4, maximum=10)
|
| 195 |
+
interm_steps = gr.Slider(label = "num of intermediate images", minimum=1, value=5, maximum=9)
|
| 196 |
guidance_scale = gr.Slider(
|
| 197 |
label="Guidance scale",
|
| 198 |
minimum=0.1,
|
|
|
|
| 259 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 260 |
submit.click(fn=generate,
|
| 261 |
inputs=[slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
| 262 |
+
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image]).then(fn=update_scales, inputs=[x, prompt, seed, steps, interm_steps, guidance_scale, avg_diff_x], outputs=[output_image, image_seq])
|
| 263 |
|
| 264 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 265 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 266 |
+
x.release(fn=update_scales, inputs=[x, prompt, seed, steps, interm_steps, guidance_scale, avg_diff_x], outputs=[output_image, image_seq], trigger_mode='always_last')
|
| 267 |
# generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
|
| 268 |
# submit_a.click(fn=generate,
|
| 269 |
# inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],
|