Spaces:
Paused
Paused
change some params (#2)
Browse files- change some params (6d5386786f4f39d609f469b329c629da89a73e1c)
- Update app.py (af37c96b745d5ba5164029f0f7fb3ac863392e00)
- Update app.py (73c7ce2c8e603c4fdf330bee3b2bda53a9f8f888)
- Update app.py (b82845b47ff423ee9196751cb78d17d3fc5460d0)
- seed (59e8fcafada993f7b134083fd0f9283456b6ed4b)
- Update app.py (7f68579294a02152ef17d11bba545f2251035f97)
- Update app.py (779d1f52c7534848d440b406ea515b896c8a6e8c)
app.py
CHANGED
|
@@ -35,6 +35,8 @@ controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Canny-alpha'
|
|
| 35 |
# pipe_controlnet = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
| 36 |
# t5_slider_controlnet = T5SliderFlux(sd_pipe=pipe_controlnet,device=torch.device("cuda"))
|
| 37 |
|
|
|
|
|
|
|
| 38 |
def convert_to_centered_scale(num):
|
| 39 |
if num <= 0:
|
| 40 |
raise ValueError("Input must be a positive integer")
|
|
@@ -49,7 +51,7 @@ def convert_to_centered_scale(num):
|
|
| 49 |
return tuple(range(start, end + 1))
|
| 50 |
|
| 51 |
@spaces.GPU(duration=200)
|
| 52 |
-
def generate(concept_1, concept_2, scale, prompt, seed=42, recalc_directions=True, iterations=200, steps=4, interm_steps=9, guidance_scale=3.5,
|
| 53 |
x_concept_1="", x_concept_2="",
|
| 54 |
avg_diff_x=None,
|
| 55 |
img2img_type = None, img = None,
|
|
@@ -57,12 +59,14 @@ def generate(concept_1, concept_2, scale, prompt, seed=42, recalc_directions=Tru
|
|
| 57 |
total_images=[],
|
| 58 |
progress=gr.Progress(track_tqdm=True)
|
| 59 |
):
|
| 60 |
-
slider_x = [
|
| 61 |
# check if avg diff for directions need to be re-calculated
|
| 62 |
print("slider_x", slider_x)
|
| 63 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
| 64 |
#torch.manual_seed(seed)
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
|
| 67 |
#avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
| 68 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
|
|
@@ -92,7 +96,7 @@ def generate(concept_1, concept_2, scale, prompt, seed=42, recalc_directions=Tru
|
|
| 92 |
post_generation_slider_update = gr.update(label=comma_concepts_x, value=0, minimum=scale_min, maximum=scale_max, interactive=True)
|
| 93 |
avg_diff_x = avg_diff.cpu()
|
| 94 |
|
| 95 |
-
return
|
| 96 |
|
| 97 |
@spaces.GPU
|
| 98 |
def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
|
|
@@ -194,7 +198,7 @@ intro = """
|
|
| 194 |
css='''
|
| 195 |
#strip, #gif{min-height: 50px}
|
| 196 |
'''
|
| 197 |
-
examples = [["winter", "summer", 1.25, "a dog in the park"]]
|
| 198 |
image_seq = gr.Image(label="Strip", elem_id="strip")
|
| 199 |
output_image = gr.Image(label="Gif", elem_id="gif")
|
| 200 |
post_generation_image = gr.Image(label="Generated Images")
|
|
@@ -218,12 +222,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 218 |
with gr.Row():
|
| 219 |
with gr.Column():
|
| 220 |
with gr.Row():
|
| 221 |
-
concept_1 = gr.Textbox(label="1st
|
| 222 |
-
concept_2 = gr.Textbox(label="2nd
|
| 223 |
#slider_x = gr.Dropdown(label="Slider concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 224 |
#slider_y = gr.Dropdown(label="Slider Y concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 225 |
-
prompt = gr.Textbox(label="Prompt", placeholder="A dog in the park")
|
| 226 |
-
x = gr.Slider(minimum=0, value=1.
|
| 227 |
submit = gr.Button("Generate directions")
|
| 228 |
gr.Examples(
|
| 229 |
examples=examples,
|
|
@@ -247,18 +251,18 @@ with gr.Blocks(css=css) as demo:
|
|
| 247 |
# generate_butt = gr.Button("generate")
|
| 248 |
|
| 249 |
with gr.Accordion(label="advanced options", open=False):
|
| 250 |
-
iterations = gr.Slider(label = "num iterations", minimum=0, value=200, maximum=
|
| 251 |
-
steps = gr.Slider(label = "num inference steps", minimum=1, value=
|
| 252 |
-
interm_steps = gr.Slider(label = "num of intermediate images", minimum=
|
| 253 |
guidance_scale = gr.Slider(
|
| 254 |
label="Guidance scale",
|
| 255 |
minimum=0.1,
|
| 256 |
maximum=10.0,
|
| 257 |
step=0.1,
|
| 258 |
-
value=5,
|
| 259 |
)
|
| 260 |
-
|
| 261 |
-
seed
|
| 262 |
|
| 263 |
|
| 264 |
# with gr.Tab(label="image2image"):
|
|
@@ -309,8 +313,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 309 |
# inputs=[slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y],
|
| 310 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 311 |
submit.click(fn=generate,
|
| 312 |
-
inputs=[concept_1, concept_2, x, prompt, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x, total_images],
|
| 313 |
-
outputs=[
|
| 314 |
|
| 315 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 316 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
|
|
|
| 35 |
# pipe_controlnet = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
| 36 |
# t5_slider_controlnet = T5SliderFlux(sd_pipe=pipe_controlnet,device=torch.device("cuda"))
|
| 37 |
|
| 38 |
+
MAX_SEED = 2**32-1
|
| 39 |
+
|
| 40 |
def convert_to_centered_scale(num):
|
| 41 |
if num <= 0:
|
| 42 |
raise ValueError("Input must be a positive integer")
|
|
|
|
| 51 |
return tuple(range(start, end + 1))
|
| 52 |
|
| 53 |
@spaces.GPU(duration=200)
|
| 54 |
+
def generate(concept_1, concept_2, scale, prompt, randomize_seed=True, seed=42, recalc_directions=True, iterations=200, steps=4, interm_steps=9, guidance_scale=3.5,
|
| 55 |
x_concept_1="", x_concept_2="",
|
| 56 |
avg_diff_x=None,
|
| 57 |
img2img_type = None, img = None,
|
|
|
|
| 59 |
total_images=[],
|
| 60 |
progress=gr.Progress(track_tqdm=True)
|
| 61 |
):
|
| 62 |
+
slider_x = [concept_2, concept_1]
|
| 63 |
# check if avg diff for directions need to be re-calculated
|
| 64 |
print("slider_x", slider_x)
|
| 65 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
| 66 |
#torch.manual_seed(seed)
|
| 67 |
+
if randomize_seed:
|
| 68 |
+
seed = random.randint(0, MAX_SEED)
|
| 69 |
+
|
| 70 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
|
| 71 |
#avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
| 72 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
|
|
|
|
| 96 |
post_generation_slider_update = gr.update(label=comma_concepts_x, value=0, minimum=scale_min, maximum=scale_max, interactive=True)
|
| 97 |
avg_diff_x = avg_diff.cpu()
|
| 98 |
|
| 99 |
+
return x_concept_1, x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas, images, images[scale_middle], post_generation_slider_update, seed
|
| 100 |
|
| 101 |
@spaces.GPU
|
| 102 |
def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
|
|
|
|
| 198 |
css='''
|
| 199 |
#strip, #gif{min-height: 50px}
|
| 200 |
'''
|
| 201 |
+
examples = [["winter", "summer", 1.25, "a dog in the park"], ["USA suburb", "Europe", 2, "a house"], ["rotten", "super fresh", 2, "a tomato"]]
|
| 202 |
image_seq = gr.Image(label="Strip", elem_id="strip")
|
| 203 |
output_image = gr.Image(label="Gif", elem_id="gif")
|
| 204 |
post_generation_image = gr.Image(label="Generated Images")
|
|
|
|
| 222 |
with gr.Row():
|
| 223 |
with gr.Column():
|
| 224 |
with gr.Row():
|
| 225 |
+
concept_1 = gr.Textbox(label="1st direction to steer", placeholder="winter")
|
| 226 |
+
concept_2 = gr.Textbox(label="2nd direction to steer", placeholder="summer")
|
| 227 |
#slider_x = gr.Dropdown(label="Slider concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 228 |
#slider_y = gr.Dropdown(label="Slider Y concept range", allow_custom_value=True, multiselect=True, max_choices=2)
|
| 229 |
+
prompt = gr.Textbox(label="Prompt", info="Describe what you to be steered by the directions", placeholder="A dog in the park")
|
| 230 |
+
x = gr.Slider(minimum=0, value=1.5, step=0.1, maximum=4.0, label="Strength", info="maximum strength on each direction (unstable beyond 2.5)")
|
| 231 |
submit = gr.Button("Generate directions")
|
| 232 |
gr.Examples(
|
| 233 |
examples=examples,
|
|
|
|
| 251 |
# generate_butt = gr.Button("generate")
|
| 252 |
|
| 253 |
with gr.Accordion(label="advanced options", open=False):
|
| 254 |
+
iterations = gr.Slider(label = "num iterations for clip directions", minimum=0, value=200, maximum=500, step=1)
|
| 255 |
+
steps = gr.Slider(label = "num inference steps", minimum=1, value=3, maximum=8, step=1)
|
| 256 |
+
interm_steps = gr.Slider(label = "num of intermediate images", minimum=3, value=21, maximum=65, step=2)
|
| 257 |
guidance_scale = gr.Slider(
|
| 258 |
label="Guidance scale",
|
| 259 |
minimum=0.1,
|
| 260 |
maximum=10.0,
|
| 261 |
step=0.1,
|
| 262 |
+
value=3.5,
|
| 263 |
)
|
| 264 |
+
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
| 265 |
+
seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, label="Seed", interactive=True, randomize=True)
|
| 266 |
|
| 267 |
|
| 268 |
# with gr.Tab(label="image2image"):
|
|
|
|
| 313 |
# inputs=[slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y],
|
| 314 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 315 |
submit.click(fn=generate,
|
| 316 |
+
inputs=[concept_1, concept_2, x, prompt, randomize_seed, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x, total_images],
|
| 317 |
+
outputs=[x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images, post_generation_image, post_generation_slider, seed])
|
| 318 |
|
| 319 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 320 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|