Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,6 @@ pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell",
|
|
25 |
|
26 |
pipe.transformer.to(memory_format=torch.channels_last)
|
27 |
pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
|
28 |
-
#pipe.enable_model_cpu_offload()
|
29 |
clip_slider = CLIPSliderFlux(pipe, device=torch.device("cuda"))
|
30 |
|
31 |
|
@@ -47,7 +46,6 @@ def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guida
|
|
47 |
# check if avg diff for directions need to be re-calculated
|
48 |
print("slider_x", slider_x)
|
49 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
50 |
-
#torch.manual_seed(seed)
|
51 |
|
52 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
|
53 |
#avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
@@ -65,8 +63,6 @@ def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guida
|
|
65 |
scale=0, scale_2nd=0,
|
66 |
seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
67 |
|
68 |
-
|
69 |
-
#comma_concepts_x = ', '.join(slider_x)
|
70 |
comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
|
71 |
|
72 |
avg_diff_x = avg_diff.cpu()
|
@@ -79,36 +75,16 @@ def update_scales(x,prompt,seed, steps, guidance_scale,
|
|
79 |
img2img_type = None, img = None,
|
80 |
controlnet_scale= None, ip_adapter_scale=None,):
|
81 |
avg_diff = avg_diff_x.cuda()
|
82 |
-
torch.manual_seed(seed)
|
83 |
if img2img_type=="controlnet canny" and img is not None:
|
84 |
control_img = process_controlnet_img(img)
|
85 |
image = t5_slider_controlnet.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=x, seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
86 |
elif img2img_type=="ip adapter" and img is not None:
|
87 |
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)
|
88 |
else:
|
89 |
-
image = clip_slider.generate(prompt,
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
@spaces.GPU
|
95 |
-
def update_x(x,y,prompt,seed, steps,
|
96 |
-
avg_diff_x, avg_diff_y,
|
97 |
-
img2img_type = None,
|
98 |
-
img = None):
|
99 |
-
avg_diff = avg_diff_x.cuda()
|
100 |
-
avg_diff_2nd = avg_diff_y.cuda()
|
101 |
-
image = clip_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
102 |
-
return image
|
103 |
-
|
104 |
-
@spaces.GPU
|
105 |
-
def update_y(x,y,prompt,seed, steps,
|
106 |
-
avg_diff_x, avg_diff_y,
|
107 |
-
img2img_type = None,
|
108 |
-
img = None):
|
109 |
-
avg_diff = avg_diff_x.cuda()
|
110 |
-
avg_diff_2nd = avg_diff_y.cuda()
|
111 |
-
image = clip_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
112 |
return image
|
113 |
|
114 |
def reset_recalc_directions():
|
|
|
25 |
|
26 |
pipe.transformer.to(memory_format=torch.channels_last)
|
27 |
pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
|
|
|
28 |
clip_slider = CLIPSliderFlux(pipe, device=torch.device("cuda"))
|
29 |
|
30 |
|
|
|
46 |
# check if avg diff for directions need to be re-calculated
|
47 |
print("slider_x", slider_x)
|
48 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
|
|
49 |
|
50 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
|
51 |
#avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
|
|
63 |
scale=0, scale_2nd=0,
|
64 |
seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
65 |
|
|
|
|
|
66 |
comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
|
67 |
|
68 |
avg_diff_x = avg_diff.cpu()
|
|
|
75 |
img2img_type = None, img = None,
|
76 |
controlnet_scale= None, ip_adapter_scale=None,):
|
77 |
avg_diff = avg_diff_x.cuda()
|
|
|
78 |
if img2img_type=="controlnet canny" and img is not None:
|
79 |
control_img = process_controlnet_img(img)
|
80 |
image = t5_slider_controlnet.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=x, seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
81 |
elif img2img_type=="ip adapter" and img is not None:
|
82 |
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)
|
83 |
else:
|
84 |
+
image = clip_slider.generate(prompt,
|
85 |
+
#guidance_scale=guidance_scale,
|
86 |
+
scale=x,
|
87 |
+
seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
return image
|
89 |
|
90 |
def reset_recalc_directions():
|