Spaces:
Runtime error
Runtime error
Update models.py
Browse files
models.py
CHANGED
|
@@ -70,7 +70,7 @@ def load_face_analysis():
|
|
| 70 |
|
| 71 |
try:
|
| 72 |
antelope_download = snapshot_download(repo_id="DIAMONIK7777/antelopev2", local_dir="/data/models/antelopev2")
|
| 73 |
-
face_app = FaceAnalysis(name='antelopev2', root='/data', providers=['
|
| 74 |
face_app.prepare(ctx_id=0, det_size=(640, 640))
|
| 75 |
return face_app, True
|
| 76 |
|
|
@@ -92,7 +92,7 @@ def load_depth_detector():
|
|
| 92 |
try:
|
| 93 |
print(" Attempting LeresDetector (highest quality)...")
|
| 94 |
leres_depth = LeresDetector.from_pretrained("lllyasviel/Annotators")
|
| 95 |
-
leres_depth.to(device)
|
| 96 |
print(" [OK] LeresDetector loaded successfully")
|
| 97 |
return leres_depth, 'leres', True
|
| 98 |
except Exception as e:
|
|
@@ -102,7 +102,7 @@ def load_depth_detector():
|
|
| 102 |
try:
|
| 103 |
print(" Attempting ZoeDetector (fallback #1)...")
|
| 104 |
zoe_depth = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
| 105 |
-
zoe_depth.to(device)
|
| 106 |
print(" [OK] ZoeDetector loaded successfully")
|
| 107 |
return zoe_depth, 'zoe', True
|
| 108 |
except Exception as e:
|
|
@@ -112,7 +112,7 @@ def load_depth_detector():
|
|
| 112 |
try:
|
| 113 |
print(" Attempting MidasDetector (fallback #2)...")
|
| 114 |
midas_depth = MidasDetector.from_pretrained("lllyasviel/Annotators")
|
| 115 |
-
midas_depth.to(device)
|
| 116 |
print(" [OK] MidasDetector loaded successfully")
|
| 117 |
return midas_depth, 'midas', True
|
| 118 |
except Exception as e:
|
|
@@ -127,7 +127,7 @@ def load_openpose_detector():
|
|
| 127 |
print("Loading OpenPose detector...")
|
| 128 |
try:
|
| 129 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
|
| 130 |
-
openpose.to(device)
|
| 131 |
print(" [OK] OpenPose loaded successfully")
|
| 132 |
return openpose, True
|
| 133 |
except Exception as e:
|
|
@@ -154,7 +154,7 @@ def load_controlnets():
|
|
| 154 |
controlnet_depth = ControlNetModel.from_pretrained(
|
| 155 |
"xinsir/controlnet-depth-sdxl-1.0",
|
| 156 |
torch_dtype=dtype
|
| 157 |
-
)
|
| 158 |
print(" [OK] ControlNet Depth loaded")
|
| 159 |
|
| 160 |
# --- NEW: Load OpenPose ControlNet ---
|
|
@@ -163,7 +163,7 @@ def load_controlnets():
|
|
| 163 |
controlnet_openpose = ControlNetModel.from_pretrained(
|
| 164 |
"xinsir/controlnet-openpose-sdxl-1.0",
|
| 165 |
torch_dtype=dtype
|
| 166 |
-
)
|
| 167 |
print(" [OK] ControlNet OpenPose loaded")
|
| 168 |
except Exception as e:
|
| 169 |
print(f" [WARNING] ControlNet OpenPose not available: {e}")
|
|
@@ -176,7 +176,7 @@ def load_controlnets():
|
|
| 176 |
"InstantX/InstantID",
|
| 177 |
subfolder="ControlNetModel",
|
| 178 |
torch_dtype=dtype
|
| 179 |
-
)
|
| 180 |
print(" [OK] InstantID ControlNet loaded successfully")
|
| 181 |
# Return all three models
|
| 182 |
return controlnet_depth, controlnet_instantid, controlnet_openpose, True
|
|
@@ -194,7 +194,7 @@ def load_image_encoder():
|
|
| 194 |
"h94/IP-Adapter",
|
| 195 |
subfolder="models/image_encoder",
|
| 196 |
torch_dtype=dtype
|
| 197 |
-
)
|
| 198 |
print(" [OK] CLIP Image Encoder loaded successfully")
|
| 199 |
return image_encoder
|
| 200 |
except Exception as e:
|
|
@@ -436,7 +436,7 @@ def load_caption_model():
|
|
| 436 |
caption_model = AutoModelForCausalLM.from_pretrained(
|
| 437 |
"microsoft/git-large-coco",
|
| 438 |
torch_dtype=dtype
|
| 439 |
-
)
|
| 440 |
print(" [OK] GIT-Large model loaded (produces detailed captions)")
|
| 441 |
return caption_processor, caption_model, True, 'git'
|
| 442 |
except Exception as e1:
|
|
@@ -451,7 +451,7 @@ def load_caption_model():
|
|
| 451 |
caption_model = BlipForConditionalGeneration.from_pretrained(
|
| 452 |
"Salesforce/blip-image-captioning-base",
|
| 453 |
torch_dtype=dtype
|
| 454 |
-
)
|
| 455 |
print(" [OK] BLIP base model loaded (standard captions)")
|
| 456 |
return caption_processor, caption_model, True, 'blip'
|
| 457 |
except Exception as e2:
|
|
|
|
| 70 |
|
| 71 |
try:
|
| 72 |
antelope_download = snapshot_download(repo_id="DIAMONIK7777/antelopev2", local_dir="/data/models/antelopev2")
|
| 73 |
+
face_app = FaceAnalysis(name='antelopev2', root='/data', providers=['CPUExecutionProvider']) # Changed from CUDA to CPU
|
| 74 |
face_app.prepare(ctx_id=0, det_size=(640, 640))
|
| 75 |
return face_app, True
|
| 76 |
|
|
|
|
| 92 |
try:
|
| 93 |
print(" Attempting LeresDetector (highest quality)...")
|
| 94 |
leres_depth = LeresDetector.from_pretrained("lllyasviel/Annotators")
|
| 95 |
+
# leres_depth.to(device)
|
| 96 |
print(" [OK] LeresDetector loaded successfully")
|
| 97 |
return leres_depth, 'leres', True
|
| 98 |
except Exception as e:
|
|
|
|
| 102 |
try:
|
| 103 |
print(" Attempting ZoeDetector (fallback #1)...")
|
| 104 |
zoe_depth = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
| 105 |
+
# zoe_depth.to(device)
|
| 106 |
print(" [OK] ZoeDetector loaded successfully")
|
| 107 |
return zoe_depth, 'zoe', True
|
| 108 |
except Exception as e:
|
|
|
|
| 112 |
try:
|
| 113 |
print(" Attempting MidasDetector (fallback #2)...")
|
| 114 |
midas_depth = MidasDetector.from_pretrained("lllyasviel/Annotators")
|
| 115 |
+
# midas_depth.to(device)
|
| 116 |
print(" [OK] MidasDetector loaded successfully")
|
| 117 |
return midas_depth, 'midas', True
|
| 118 |
except Exception as e:
|
|
|
|
| 127 |
print("Loading OpenPose detector...")
|
| 128 |
try:
|
| 129 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
|
| 130 |
+
# openpose.to(device)
|
| 131 |
print(" [OK] OpenPose loaded successfully")
|
| 132 |
return openpose, True
|
| 133 |
except Exception as e:
|
|
|
|
| 154 |
controlnet_depth = ControlNetModel.from_pretrained(
|
| 155 |
"xinsir/controlnet-depth-sdxl-1.0",
|
| 156 |
torch_dtype=dtype
|
| 157 |
+
)#.to(device)
|
| 158 |
print(" [OK] ControlNet Depth loaded")
|
| 159 |
|
| 160 |
# --- NEW: Load OpenPose ControlNet ---
|
|
|
|
| 163 |
controlnet_openpose = ControlNetModel.from_pretrained(
|
| 164 |
"xinsir/controlnet-openpose-sdxl-1.0",
|
| 165 |
torch_dtype=dtype
|
| 166 |
+
)#.to(device)
|
| 167 |
print(" [OK] ControlNet OpenPose loaded")
|
| 168 |
except Exception as e:
|
| 169 |
print(f" [WARNING] ControlNet OpenPose not available: {e}")
|
|
|
|
| 176 |
"InstantX/InstantID",
|
| 177 |
subfolder="ControlNetModel",
|
| 178 |
torch_dtype=dtype
|
| 179 |
+
)#.to(device)
|
| 180 |
print(" [OK] InstantID ControlNet loaded successfully")
|
| 181 |
# Return all three models
|
| 182 |
return controlnet_depth, controlnet_instantid, controlnet_openpose, True
|
|
|
|
| 194 |
"h94/IP-Adapter",
|
| 195 |
subfolder="models/image_encoder",
|
| 196 |
torch_dtype=dtype
|
| 197 |
+
)#.to(device)
|
| 198 |
print(" [OK] CLIP Image Encoder loaded successfully")
|
| 199 |
return image_encoder
|
| 200 |
except Exception as e:
|
|
|
|
| 436 |
caption_model = AutoModelForCausalLM.from_pretrained(
|
| 437 |
"microsoft/git-large-coco",
|
| 438 |
torch_dtype=dtype
|
| 439 |
+
)#.to(device)
|
| 440 |
print(" [OK] GIT-Large model loaded (produces detailed captions)")
|
| 441 |
return caption_processor, caption_model, True, 'git'
|
| 442 |
except Exception as e1:
|
|
|
|
| 451 |
caption_model = BlipForConditionalGeneration.from_pretrained(
|
| 452 |
"Salesforce/blip-image-captioning-base",
|
| 453 |
torch_dtype=dtype
|
| 454 |
+
)#.to(device)
|
| 455 |
print(" [OK] BLIP base model loaded (standard captions)")
|
| 456 |
return caption_processor, caption_model, True, 'blip'
|
| 457 |
except Exception as e2:
|