Spaces:
Paused
Paused
uuu
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ import torch
|
|
| 12 |
from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel
|
| 13 |
from diffusers.utils import load_image
|
| 14 |
from image_gen_aux import DepthPreprocessor
|
|
|
|
| 15 |
|
| 16 |
# ----------------------------
|
| 17 |
# Step 1: Download IP Adapter if not exists
|
|
@@ -51,18 +52,21 @@ image_encoder_path = "google/siglip-so400m-patch14-384"
|
|
| 51 |
|
| 52 |
|
| 53 |
controlnet = SD3ControlNetModel.from_pretrained("stabilityai/stable-diffusion-3.5-large-controlnet-depth", torch_dtype=torch.float16)
|
| 54 |
-
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 55 |
-
"stabilityai/stable-diffusion-3.5-large",
|
| 56 |
-
controlnet=controlnet,
|
| 57 |
-
torch_dtype=torch.float16,
|
| 58 |
-
).to("cuda")
|
| 59 |
|
| 60 |
-
|
| 61 |
ip_adapter_path=ip_adapter_path,
|
| 62 |
image_encoder_path=image_encoder_path,
|
| 63 |
nb_token=64,
|
|
|
|
| 64 |
)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
# ----------------------------
|
|
@@ -77,6 +81,8 @@ def gui_generation(prompt,negative_prompt, ref_img, guidance_scale, ipadapter_sc
|
|
| 77 |
control_image = depth_preprocessor(image, invert=True)[0].convert("RGB")
|
| 78 |
|
| 79 |
generator = torch.Generator(device="cpu").manual_seed(0)
|
|
|
|
|
|
|
| 80 |
image = pipe(
|
| 81 |
width=1024,
|
| 82 |
height=1024,
|
|
@@ -88,7 +94,6 @@ def gui_generation(prompt,negative_prompt, ref_img, guidance_scale, ipadapter_sc
|
|
| 88 |
num_inference_steps=40,
|
| 89 |
generator=generator,
|
| 90 |
max_sequence_length=77,
|
| 91 |
-
ipadapter_scale=ipadapter_scale,
|
| 92 |
).images[0]
|
| 93 |
|
| 94 |
return image
|
|
|
|
| 12 |
from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel
|
| 13 |
from diffusers.utils import load_image
|
| 14 |
from image_gen_aux import DepthPreprocessor
|
| 15 |
+
from diffusers.models import SD3ControlNetModel, T2IAdapter
|
| 16 |
|
| 17 |
# ----------------------------
|
| 18 |
# Step 1: Download IP Adapter if not exists
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
controlnet = SD3ControlNetModel.from_pretrained("stabilityai/stable-diffusion-3.5-large-controlnet-depth", torch_dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
adapter = T2IAdapter.from_pretrained(
|
| 57 |
ip_adapter_path=ip_adapter_path,
|
| 58 |
image_encoder_path=image_encoder_path,
|
| 59 |
nb_token=64,
|
| 60 |
+
torch_dtype=torch.float16
|
| 61 |
)
|
| 62 |
|
| 63 |
+
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 64 |
+
"stabilityai/stable-diffusion-3.5-large",
|
| 65 |
+
controlnet=controlnet,adapter=adapter,
|
| 66 |
+
torch_dtype=torch.float16,
|
| 67 |
+
).to("cuda")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
|
| 71 |
|
| 72 |
# ----------------------------
|
|
|
|
| 81 |
control_image = depth_preprocessor(image, invert=True)[0].convert("RGB")
|
| 82 |
|
| 83 |
generator = torch.Generator(device="cpu").manual_seed(0)
|
| 84 |
+
pipe.set_ip_adapter_scale(ipadapter_scale) # Adjust the scale as needed
|
| 85 |
+
|
| 86 |
image = pipe(
|
| 87 |
width=1024,
|
| 88 |
height=1024,
|
|
|
|
| 94 |
num_inference_steps=40,
|
| 95 |
generator=generator,
|
| 96 |
max_sequence_length=77,
|
|
|
|
| 97 |
).images[0]
|
| 98 |
|
| 99 |
return image
|