Update handler.py
Browse files- handler.py +10 -7
handler.py
CHANGED
|
@@ -13,6 +13,8 @@ from insightface.app import FaceAnalysis
|
|
| 13 |
from style_template import styles
|
| 14 |
from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
|
| 15 |
from controlnet_aux import OpenposeDetector
|
|
|
|
|
|
|
| 16 |
import os
|
| 17 |
from huggingface_hub import hf_hub_download
|
| 18 |
import base64
|
|
@@ -56,13 +58,14 @@ class EndpointHandler:
|
|
| 56 |
controlnet_model = hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 57 |
face_adapter = hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
self.face_analyzer.prepare(ctx_id=0, det_size=(640, 640))
|
| 65 |
|
|
|
|
|
|
|
| 66 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 67 |
|
| 68 |
# Path to InstantID models
|
|
@@ -259,7 +262,7 @@ class EndpointHandler:
|
|
| 259 |
face_kps = draw_kps(face_image, np.array([[x, y], [x1, y1]])) # Placeholder keypoints
|
| 260 |
|
| 261 |
# Analyze the face using InsightFace
|
| 262 |
-
face_info = self.
|
| 263 |
|
| 264 |
if not face_info:
|
| 265 |
return {"error": "Face analysis failed."}
|
|
|
|
| 13 |
from style_template import styles
|
| 14 |
from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
|
| 15 |
from controlnet_aux import OpenposeDetector
|
| 16 |
+
import torch.nn.functional as F
|
| 17 |
+
from torchvision.transforms import Compose
|
| 18 |
import os
|
| 19 |
from huggingface_hub import hf_hub_download
|
| 20 |
import base64
|
|
|
|
| 58 |
controlnet_model = hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 59 |
face_adapter = hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 60 |
|
| 61 |
+
dir_path = os.path.join(model_dir, "models", "face_detection_yunet_2023mar_int8.onnx")
|
| 62 |
+
if not os.path.exists(dir_path):
|
| 63 |
+
raise RuntimeError(f"Model path {dir_path} does not exist.")
|
| 64 |
+
else:
|
| 65 |
+
self.face_net = cv2.dnn.readNet(dir_path)
|
|
|
|
| 66 |
|
| 67 |
+
self.app = FaceAnalysis(name='model', root=model_dir, providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
| 68 |
+
self.app.prepare(ctx_id=0, det_size=(640, 640))
|
| 69 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 70 |
|
| 71 |
# Path to InstantID models
|
|
|
|
| 262 |
face_kps = draw_kps(face_image, np.array([[x, y], [x1, y1]])) # Placeholder keypoints
|
| 263 |
|
| 264 |
# Analyze the face using InsightFace
|
| 265 |
+
face_info = self.app.get(face_image_cv2)
|
| 266 |
|
| 267 |
if not face_info:
|
| 268 |
return {"error": "Face analysis failed."}
|