Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -71,24 +71,28 @@ def verify_file_exists(folder: str, filename: str) -> bool:
|
|
71 |
|
72 |
# 7. Download de Modelos
|
73 |
logger.info("Baixando modelos necessários...")
|
74 |
-
|
75 |
-
("black-forest-labs/FLUX.1-Redux-dev",
|
76 |
-
|
77 |
-
|
78 |
-
("
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
92 |
|
93 |
# 8. Inicialização dos Modelos
|
94 |
logger.info("Inicializando modelos...")
|
@@ -102,20 +106,26 @@ try:
|
|
102 |
clip_name2="ViT-L-14-TEXT-detail-improved-hiT-GmP-TE-only-HF.safetensors",
|
103 |
type="flux"
|
104 |
)
|
|
|
|
|
105 |
|
106 |
# CLIP Vision
|
107 |
logger.info("Carregando CLIP Vision...")
|
108 |
clipvisionloader = NODE_CLASS_MAPPINGS["CLIPVisionLoader"]()
|
109 |
CLIP_VISION = clipvisionloader.load_clip(
|
110 |
-
clip_name="
|
111 |
)
|
|
|
|
|
112 |
|
113 |
-
# Style Model
|
114 |
logger.info("Carregando Style Model...")
|
115 |
stylemodelloader = NODE_CLASS_MAPPINGS["StyleModelLoader"]()
|
116 |
STYLE_MODEL = stylemodelloader.load_style_model(
|
117 |
style_model_name="flux1-redux-dev.safetensors"
|
118 |
)
|
|
|
|
|
119 |
|
120 |
# VAE
|
121 |
logger.info("Carregando VAE...")
|
@@ -123,6 +133,8 @@ try:
|
|
123 |
VAE_MODEL = vaeloader.load_vae(
|
124 |
vae_name="ae.safetensors"
|
125 |
)
|
|
|
|
|
126 |
|
127 |
# UNET
|
128 |
logger.info("Carregando UNET...")
|
@@ -131,13 +143,16 @@ try:
|
|
131 |
unet_name="flux1-dev.safetensors",
|
132 |
weight_dtype="fp8_e4m3fn"
|
133 |
)
|
|
|
|
|
134 |
|
135 |
logger.info("Carregando modelos na GPU...")
|
136 |
-
model_loaders = [CLIP_MODEL, VAE_MODEL,
|
137 |
model_management.load_models_gpu([
|
138 |
loader[0].patcher if hasattr(loader[0], 'patcher') else loader[0]
|
139 |
for loader in model_loaders
|
140 |
])
|
|
|
141 |
except Exception as e:
|
142 |
logger.error(f"Erro ao inicializar modelos: {str(e)}")
|
143 |
raise
|
|
|
71 |
|
72 |
# 7. Download de Modelos
|
73 |
logger.info("Baixando modelos necessários...")
|
74 |
+
try:
|
75 |
+
hf_hub_download(repo_id="black-forest-labs/FLUX.1-Redux-dev",
|
76 |
+
filename="flux1-redux-dev.safetensors",
|
77 |
+
local_dir=os.path.join(models_dir, "style_models"))
|
78 |
+
hf_hub_download(repo_id="comfyanonymous/flux_text_encoders",
|
79 |
+
filename="t5xxl_fp16.safetensors",
|
80 |
+
local_dir=os.path.join(models_dir, "text_encoders"))
|
81 |
+
hf_hub_download(repo_id="zer0int/CLIP-GmP-ViT-L-14",
|
82 |
+
filename="ViT-L-14-TEXT-detail-improved-hiT-GmP-TE-only-HF.safetensors",
|
83 |
+
local_dir=os.path.join(models_dir, "text_encoders"))
|
84 |
+
hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev",
|
85 |
+
filename="ae.safetensors",
|
86 |
+
local_dir=os.path.join(models_dir, "vae"))
|
87 |
+
hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev",
|
88 |
+
filename="flux1-dev.safetensors",
|
89 |
+
local_dir=os.path.join(models_dir, "unet"))
|
90 |
+
hf_hub_download(repo_id="Comfy-Org/sigclip_vision_384",
|
91 |
+
filename="model.safetensors",
|
92 |
+
local_dir=os.path.join(models_dir, "clip_vision"))
|
93 |
+
except Exception as e:
|
94 |
+
logger.error(f"Erro ao baixar modelos: {str(e)}")
|
95 |
+
raise
|
96 |
|
97 |
# 8. Inicialização dos Modelos
|
98 |
logger.info("Inicializando modelos...")
|
|
|
106 |
clip_name2="ViT-L-14-TEXT-detail-improved-hiT-GmP-TE-only-HF.safetensors",
|
107 |
type="flux"
|
108 |
)
|
109 |
+
if CLIP_MODEL is None:
|
110 |
+
raise ValueError("Falha ao carregar CLIP model")
|
111 |
|
112 |
# CLIP Vision
|
113 |
logger.info("Carregando CLIP Vision...")
|
114 |
clipvisionloader = NODE_CLASS_MAPPINGS["CLIPVisionLoader"]()
|
115 |
CLIP_VISION = clipvisionloader.load_clip(
|
116 |
+
clip_name="model.safetensors"
|
117 |
)
|
118 |
+
if CLIP_VISION is None:
|
119 |
+
raise ValueError("Falha ao carregar CLIP Vision model")
|
120 |
|
121 |
+
# Style Model (Carregado separadamente)
|
122 |
logger.info("Carregando Style Model...")
|
123 |
stylemodelloader = NODE_CLASS_MAPPINGS["StyleModelLoader"]()
|
124 |
STYLE_MODEL = stylemodelloader.load_style_model(
|
125 |
style_model_name="flux1-redux-dev.safetensors"
|
126 |
)
|
127 |
+
if STYLE_MODEL is None:
|
128 |
+
raise ValueError("Falha ao carregar Style Model")
|
129 |
|
130 |
# VAE
|
131 |
logger.info("Carregando VAE...")
|
|
|
133 |
VAE_MODEL = vaeloader.load_vae(
|
134 |
vae_name="ae.safetensors"
|
135 |
)
|
136 |
+
if VAE_MODEL is None:
|
137 |
+
raise ValueError("Falha ao carregar VAE model")
|
138 |
|
139 |
# UNET
|
140 |
logger.info("Carregando UNET...")
|
|
|
143 |
unet_name="flux1-dev.safetensors",
|
144 |
weight_dtype="fp8_e4m3fn"
|
145 |
)
|
146 |
+
if UNET_MODEL is None:
|
147 |
+
raise ValueError("Falha ao carregar UNET model")
|
148 |
|
149 |
logger.info("Carregando modelos na GPU...")
|
150 |
+
model_loaders = [CLIP_MODEL, VAE_MODEL, CLIP_VISION, UNET_MODEL]
|
151 |
model_management.load_models_gpu([
|
152 |
loader[0].patcher if hasattr(loader[0], 'patcher') else loader[0]
|
153 |
for loader in model_loaders
|
154 |
])
|
155 |
+
logger.info("Modelos carregados com sucesso")
|
156 |
except Exception as e:
|
157 |
logger.error(f"Erro ao inicializar modelos: {str(e)}")
|
158 |
raise
|