Spaces:
Runtime error
Runtime error
Update processing/setup.py
Browse files- processing/setup.py +15 -31
processing/setup.py
CHANGED
|
@@ -1,21 +1,20 @@
|
|
| 1 |
import huggingface_hub
|
| 2 |
import torch
|
| 3 |
-
from diffusers import ControlNetModel, StableDiffusionXLControlNetInpaintPipeline
|
|
|
|
| 4 |
from DPT.dpt.models import DPTDepthModel
|
| 5 |
from ip_adapter import IPAdapter, IPAdapterXL
|
| 6 |
from ip_adapter.utils import register_cross_attention_hook
|
| 7 |
|
|
|
|
| 8 |
def setup(base_model_path="stabilityai/stable-diffusion-xl-base-1.0",
|
| 9 |
image_encoder_path="sdxl_models/image_encoder",
|
| 10 |
ip_ckpt="sdxl_models/ip-adapter_sdxl.bin",
|
| 11 |
controlnet_path="diffusers/controlnet-depth-sdxl-1.0",
|
| 12 |
-
lora_model_path="PixelArt_v1_LoRA_XL", # Path to your LoRA model
|
| 13 |
device="cuda",
|
| 14 |
model_depth_path="DPT/weights/dpt_hybrid-midas-501f0c75.pt",
|
| 15 |
depth_backbone="vitb_rn50_384"):
|
| 16 |
-
"""Set up the processing module
|
| 17 |
-
|
| 18 |
-
# Ensure that the necessary files are downloaded locally
|
| 19 |
huggingface_hub.snapshot_download(
|
| 20 |
repo_id='h94/IP-Adapter',
|
| 21 |
allow_patterns=[
|
|
@@ -25,17 +24,12 @@ def setup(base_model_path="stabilityai/stable-diffusion-xl-base-1.0",
|
|
| 25 |
local_dir='./',
|
| 26 |
local_dir_use_symlinks=False,
|
| 27 |
)
|
| 28 |
-
|
| 29 |
-
torch.cuda.empty_cache()
|
| 30 |
|
| 31 |
-
|
| 32 |
-
controlnet = ControlNetModel.from_pretrained(
|
| 33 |
-
controlnet_path,
|
| 34 |
-
use_safetensors=True,
|
| 35 |
-
torch_dtype=torch.float16
|
| 36 |
-
).to(device)
|
| 37 |
|
| 38 |
-
#
|
|
|
|
|
|
|
| 39 |
pipe = StableDiffusionXLControlNetInpaintPipeline.from_pretrained(
|
| 40 |
base_model_path,
|
| 41 |
controlnet=controlnet,
|
|
@@ -43,31 +37,21 @@ def setup(base_model_path="stabilityai/stable-diffusion-xl-base-1.0",
|
|
| 43 |
torch_dtype=torch.float16,
|
| 44 |
add_watermarker=False,
|
| 45 |
).to(device)
|
| 46 |
-
|
| 47 |
-
# Register cross-attention hook for IP Adapter
|
| 48 |
pipe.unet = register_cross_attention_hook(pipe.unet)
|
| 49 |
-
|
| 50 |
-
# Initialize IP Adapter model
|
| 51 |
ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device)
|
| 52 |
-
|
| 53 |
-
# Load LoRA weights into the Stable Diffusion pipeline
|
| 54 |
-
pipe.load_lora_weights(
|
| 55 |
-
lora_model_path,
|
| 56 |
-
weight_name="PixelArt_v1_LoRA_XL.safetensors", # Replace with your actual LoRA filename
|
| 57 |
-
adapter_name="pixelart"
|
| 58 |
-
)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
-
# Set up the DPT Depth Model for depth map generation
|
| 65 |
model = DPTDepthModel(
|
| 66 |
path=model_depth_path,
|
| 67 |
backbone=depth_backbone,
|
| 68 |
non_negative=True,
|
| 69 |
enable_attention_hooks=False,
|
| 70 |
-
)
|
|
|
|
| 71 |
model.eval()
|
| 72 |
|
| 73 |
-
return [ip_model, model
|
|
|
|
| 1 |
import huggingface_hub
|
| 2 |
import torch
|
| 3 |
+
from diffusers import ControlNetModel, StableDiffusionXLControlNetInpaintPipeline
|
| 4 |
+
|
| 5 |
from DPT.dpt.models import DPTDepthModel
|
| 6 |
from ip_adapter import IPAdapter, IPAdapterXL
|
| 7 |
from ip_adapter.utils import register_cross_attention_hook
|
| 8 |
|
| 9 |
+
|
| 10 |
def setup(base_model_path="stabilityai/stable-diffusion-xl-base-1.0",
|
| 11 |
image_encoder_path="sdxl_models/image_encoder",
|
| 12 |
ip_ckpt="sdxl_models/ip-adapter_sdxl.bin",
|
| 13 |
controlnet_path="diffusers/controlnet-depth-sdxl-1.0",
|
|
|
|
| 14 |
device="cuda",
|
| 15 |
model_depth_path="DPT/weights/dpt_hybrid-midas-501f0c75.pt",
|
| 16 |
depth_backbone="vitb_rn50_384"):
|
| 17 |
+
"""Set up the processing module."""
|
|
|
|
|
|
|
| 18 |
huggingface_hub.snapshot_download(
|
| 19 |
repo_id='h94/IP-Adapter',
|
| 20 |
allow_patterns=[
|
|
|
|
| 24 |
local_dir='./',
|
| 25 |
local_dir_use_symlinks=False,
|
| 26 |
)
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# load SDXL pipeline
|
| 31 |
+
controlnet = ControlNetModel.from_pretrained(controlnet_path, use_safetensors=True,
|
| 32 |
+
torch_dtype=torch.float16).to(device)
|
| 33 |
pipe = StableDiffusionXLControlNetInpaintPipeline.from_pretrained(
|
| 34 |
base_model_path,
|
| 35 |
controlnet=controlnet,
|
|
|
|
| 37 |
torch_dtype=torch.float16,
|
| 38 |
add_watermarker=False,
|
| 39 |
).to(device)
|
|
|
|
|
|
|
| 40 |
pipe.unet = register_cross_attention_hook(pipe.unet)
|
| 41 |
+
|
|
|
|
| 42 |
ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
"""
|
| 45 |
+
Get Depth Model Ready
|
| 46 |
+
"""
|
| 47 |
|
|
|
|
| 48 |
model = DPTDepthModel(
|
| 49 |
path=model_depth_path,
|
| 50 |
backbone=depth_backbone,
|
| 51 |
non_negative=True,
|
| 52 |
enable_attention_hooks=False,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
model.eval()
|
| 56 |
|
| 57 |
+
return [ip_model, model]
|