Update handler.py
Browse files- handler.py +6 -1
handler.py
CHANGED
|
@@ -16,6 +16,7 @@ from controlnet_aux import OpenposeDetector
|
|
| 16 |
import torch.nn.functional as F
|
| 17 |
from torchvision.transforms import Compose
|
| 18 |
import os
|
|
|
|
| 19 |
|
| 20 |
# global variable
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -25,6 +26,11 @@ DEFAULT_STYLE_NAME = "Spring Festival"
|
|
| 25 |
|
| 26 |
class EndpointHandler:
|
| 27 |
def __init__(self, model_dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
dir_path = os.path.join(model_dir, "models", "antelopev2")
|
| 29 |
if not os.path.exists(dir_path):
|
| 30 |
print(f"Model path {dir_path} does not exist. Attempting to download.")
|
|
@@ -37,7 +43,6 @@ class EndpointHandler:
|
|
| 37 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 38 |
|
| 39 |
# Path to InstantID models
|
| 40 |
-
face_adapter = os.path.join(model_dir, "checkpoints", "ip-adapter.bin")
|
| 41 |
controlnet_path = os.path.join(model_dir, "checkpoints", "ControlNetModel")
|
| 42 |
|
| 43 |
# Load pipeline face ControlNetModel
|
|
|
|
| 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 |
|
| 21 |
# global variable
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 26 |
|
| 27 |
class EndpointHandler:
|
| 28 |
def __init__(self, model_dir):
|
| 29 |
+
# Ensure the necessary files are downloaded
|
| 30 |
+
controlnet_config = hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/config.json", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 31 |
+
controlnet_model = hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 32 |
+
face_adapter = hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir=os.path.join(model_dir, "checkpoints"))
|
| 33 |
+
|
| 34 |
dir_path = os.path.join(model_dir, "models", "antelopev2")
|
| 35 |
if not os.path.exists(dir_path):
|
| 36 |
print(f"Model path {dir_path} does not exist. Attempting to download.")
|
|
|
|
| 43 |
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 44 |
|
| 45 |
# Path to InstantID models
|
|
|
|
| 46 |
controlnet_path = os.path.join(model_dir, "checkpoints", "ControlNetModel")
|
| 47 |
|
| 48 |
# Load pipeline face ControlNetModel
|