Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix refactor face model path config #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions comfy-nodes/external_face_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from PIL import Image, ImageOps
import numpy as np
import torch
import os
import uuid
import requests
import folder_paths


reactor_models_relative_path = "reactor/faces"
reactor_face_models_path = os.path.join(folder_paths.models_dir, reactor_models_relative_path)
os.makedirs(reactor_face_models_path, exist_ok=True)
folder_paths.folder_names_and_paths[reactor_models_relative_path] = (
[reactor_face_models_path], folder_paths.supported_pt_extensions
)


class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
Expand All @@ -13,6 +21,7 @@ def __ne__(self, __value: object) -> bool:


class ComfyUIDeployExternalFaceModel:

@classmethod
def INPUT_TYPES(s):
return {
Expand All @@ -24,10 +33,11 @@ def INPUT_TYPES(s):
},
"optional": {
"default_face_model_name": (
"STRING",
{"multiline": False, "default": ""},
folder_paths.get_filename_list(reactor_models_relative_path),
),
"face_model_save_name": ( # if `default_face_model_name` is a link to download a file, we will attempt to save it with this name

# if `default_face_model_name` is a link to download a file, we will attempt to save it with this name
"face_model_save_name": (
"STRING",
{"multiline": False, "default": ""},
),
Expand All @@ -48,9 +58,7 @@ def INPUT_TYPES(s):

RETURN_TYPES = (WILDCARD,)
RETURN_NAMES = ("path",)

FUNCTION = "run"

CATEGORY = "deploy"

def run(
Expand All @@ -62,26 +70,27 @@ def run(
description=None,
face_model_url=None,
):
import requests
import os
import uuid

if face_model_url and face_model_url.startswith("http"):
if face_model_save_name:
existing_face_models = folder_paths.get_filename_list("reactor/faces")
existing_face_models = folder_paths.get_filename_list(reactor_models_relative_path)
# Check if face_model_save_name exists in the list
if face_model_save_name in existing_face_models:
print(f"using face model: {face_model_save_name}")
return (face_model_save_name,)
else:
face_model_save_name = str(uuid.uuid4()) + ".safetensors"
print(face_model_save_name)
print(folder_paths.folder_names_and_paths["reactor/faces"][0][0])
file_name = face_model_url.split("?")[0].rsplit("/", maxsplit=1)[-1]
file_extensions = '.' + file_name.rsplit(".", maxsplit=1)[-1]
if file_extensions in folder_paths.supported_pt_extensions:
face_model_save_name = file_name[:40]
else:
face_model_save_name = "reactor_model_" + str(uuid.uuid4())[:8] + ".safetensors"
print(face_model_save_name)

destination_path = os.path.join(
folder_paths.folder_names_and_paths["reactor/faces"][0][0],
reactor_face_models_path,
face_model_save_name,
)

print(destination_path)
print(
"Downloading external face model - "
Expand All @@ -105,4 +114,4 @@ def run(
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalFaceModel": ComfyUIDeployExternalFaceModel}
NODE_DISPLAY_NAME_MAPPINGS = {
"ComfyUIDeployExternalFaceModel": "External Face Model (ComfyUI Deploy)"
}
}