Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,15 +11,63 @@ from comfy import model_management
|
|
| 11 |
|
| 12 |
# Download required models
|
| 13 |
t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp8_e4m3fn.safetensors", local_dir="models/text_encoders/")
|
| 14 |
-
vae_path = hf_hub_download(repo_id="
|
| 15 |
unet_path = hf_hub_download(repo_id="lodestones/Chroma", filename="chroma-unlocked-v31.safetensors", local_dir="models/unet")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
NODE_CLASS_MAPPINGS,
|
| 24 |
CLIPTextEncode,
|
| 25 |
CLIPLoader,
|
|
@@ -29,11 +77,6 @@ from my_workflow import (
|
|
| 29 |
SaveImage,
|
| 30 |
)
|
| 31 |
|
| 32 |
-
# Initialize ComfyUI
|
| 33 |
-
add_comfyui_directory_to_sys_path()
|
| 34 |
-
add_extra_model_paths()
|
| 35 |
-
import_custom_nodes()
|
| 36 |
-
|
| 37 |
# Initialize all model loaders outside the function
|
| 38 |
randomnoise = NODE_CLASS_MAPPINGS["RandomNoise"]()
|
| 39 |
emptysd3latentimage = NODE_CLASS_MAPPINGS["EmptySD3LatentImage"]()
|
|
|
|
| 11 |
|
| 12 |
# Download required models
|
| 13 |
t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp8_e4m3fn.safetensors", local_dir="models/text_encoders/")
|
| 14 |
+
vae_path = hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev", filename="ae.safetensors", local_dir="models/vae")
|
| 15 |
unet_path = hf_hub_download(repo_id="lodestones/Chroma", filename="chroma-unlocked-v31.safetensors", local_dir="models/unet")
|
| 16 |
|
| 17 |
+
# Utility functions
|
| 18 |
+
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
| 19 |
+
try:
|
| 20 |
+
return obj[index]
|
| 21 |
+
except KeyError:
|
| 22 |
+
return obj["result"][index]
|
| 23 |
+
|
| 24 |
+
def find_path(name: str, path: str = None) -> str:
|
| 25 |
+
if path is None:
|
| 26 |
+
path = os.getcwd()
|
| 27 |
+
if name in os.listdir(path):
|
| 28 |
+
path_name = os.path.join(path, name)
|
| 29 |
+
print(f"{name} found: {path_name}")
|
| 30 |
+
return path_name
|
| 31 |
+
parent_directory = os.path.dirname(path)
|
| 32 |
+
if parent_directory == path:
|
| 33 |
+
return None
|
| 34 |
+
return find_path(name, parent_directory)
|
| 35 |
+
|
| 36 |
+
def add_comfyui_directory_to_sys_path() -> None:
|
| 37 |
+
comfyui_path = find_path("ComfyUI")
|
| 38 |
+
if comfyui_path is not None and os.path.isdir(comfyui_path):
|
| 39 |
+
sys.path.append(comfyui_path)
|
| 40 |
+
print(f"'{comfyui_path}' added to sys.path")
|
| 41 |
+
|
| 42 |
+
def add_extra_model_paths() -> None:
|
| 43 |
+
try:
|
| 44 |
+
from main import load_extra_path_config
|
| 45 |
+
except ImportError:
|
| 46 |
+
from utils.extra_config import load_extra_path_config
|
| 47 |
+
extra_model_paths = find_path("extra_model_paths.yaml")
|
| 48 |
+
if extra_model_paths is not None:
|
| 49 |
+
load_extra_path_config(extra_model_paths)
|
| 50 |
+
else:
|
| 51 |
+
print("Could not find the extra_model_paths config file.")
|
| 52 |
+
|
| 53 |
+
def import_custom_nodes() -> None:
|
| 54 |
+
import asyncio
|
| 55 |
+
import execution
|
| 56 |
+
from nodes import init_extra_nodes
|
| 57 |
+
import server
|
| 58 |
+
loop = asyncio.new_event_loop()
|
| 59 |
+
asyncio.set_event_loop(loop)
|
| 60 |
+
server_instance = server.PromptServer(loop)
|
| 61 |
+
execution.PromptQueue(server_instance)
|
| 62 |
+
init_extra_nodes()
|
| 63 |
+
|
| 64 |
+
# Initialize paths
|
| 65 |
+
add_comfyui_directory_to_sys_path()
|
| 66 |
+
add_extra_model_paths()
|
| 67 |
+
import_custom_nodes()
|
| 68 |
+
|
| 69 |
+
# Import all necessary nodes
|
| 70 |
+
from nodes import (
|
| 71 |
NODE_CLASS_MAPPINGS,
|
| 72 |
CLIPTextEncode,
|
| 73 |
CLIPLoader,
|
|
|
|
| 77 |
SaveImage,
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# Initialize all model loaders outside the function
|
| 81 |
randomnoise = NODE_CLASS_MAPPINGS["RandomNoise"]()
|
| 82 |
emptysd3latentimage = NODE_CLASS_MAPPINGS["EmptySD3LatentImage"]()
|