primerz commited on
Commit
064a79e
·
verified ·
1 Parent(s): 6620b3e

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +8 -23
model.py CHANGED
@@ -11,7 +11,7 @@ from diffusers import (
11
  # Import the custom pipeline from your local file
12
  from pipeline_stable_diffusion_xl_instantid_img2img import StableDiffusionXLInstantIDImg2ImgPipeline
13
 
14
- from huggingface_hub import snapshot_download, hf_hub_download # <-- ADDED hf_hub_download
15
  from insightface.app import FaceAnalysis
16
  from controlnet_aux import ZoeDetector, LineartDetector
17
 
@@ -65,28 +65,13 @@ class ModelHandler:
65
  # 2. Load ControlNets
66
  print("Loading ControlNets (InstantID, Zoe, LineArt)...")
67
 
68
- # --- START FIX for OSError ---
69
- # We must first download the InstantID ControlNet files to a local path.
70
- controlnet_local_path = "./models/InstantID-ControlNet"
71
- if not os.path.exists(os.path.join(controlnet_local_path, "config.json")):
72
- print(f"Downloading InstantID ControlNet to {controlnet_local_path}...")
73
- hf_hub_download(
74
- repo_id=Config.INSTANTID_REPO,
75
- filename="controlnet/config.json",
76
- local_dir=controlnet_local_path,
77
- local_dir_use_symlinks=False
78
- )
79
- hf_hub_download(
80
- repo_id=Config.INSTANTID_REPO,
81
- filename="controlnet/diffusion_pytorch_model.safetensors",
82
- local_dir=controlnet_local_path,
83
- local_dir_use_symlinks=False
84
- )
85
-
86
- # Now, load the ControlNet from the LOCAL directory
87
- print("Loading InstantID ControlNet from local files...")
88
  cn_instantid = ControlNetModel.from_pretrained(
89
- controlnet_local_path, # <-- Load from local path
 
90
  torch_dtype=Config.DTYPE
91
  )
92
  print(" [OK] Loaded InstantID ControlNet.")
@@ -141,7 +126,7 @@ class ModelHandler:
141
  return None
142
 
143
  # Sort by size (width * height) to find the main character
144
- faces = sorted(faces, key=lambda x: (x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x['bbox'][1]), reverse=True)
145
 
146
  # Return the largest face
147
  return torch.tensor(faces[0].normed_embedding).unsqueeze(0)
 
11
  # Import the custom pipeline from your local file
12
  from pipeline_stable_diffusion_xl_instantid_img2img import StableDiffusionXLInstantIDImg2ImgPipeline
13
 
14
+ from huggingface_hub import snapshot_download
15
  from insightface.app import FaceAnalysis
16
  from controlnet_aux import ZoeDetector, LineartDetector
17
 
 
65
  # 2. Load ControlNets
66
  print("Loading ControlNets (InstantID, Zoe, LineArt)...")
67
 
68
+ # --- START FIX ---
69
+ # Load the InstantID ControlNet from the correct subfolder
70
+ # pointed out by the user.
71
+ print("Loading InstantID ControlNet from subfolder 'ControlNetModel'...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  cn_instantid = ControlNetModel.from_pretrained(
73
+ Config.INSTANTID_REPO, # "InstantX/InstantID"
74
+ subfolder="ControlNetModel", # <-- THE FIX
75
  torch_dtype=Config.DTYPE
76
  )
77
  print(" [OK] Loaded InstantID ControlNet.")
 
126
  return None
127
 
128
  # Sort by size (width * height) to find the main character
129
+ faces = sorted(faces, key=lambda x: (x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x_bbox[1]), reverse=True)
130
 
131
  # Return the largest face
132
  return torch.tensor(faces[0].normed_embedding).unsqueeze(0)