nftnik commited on
Commit
7a2be17
·
verified ·
1 Parent(s): 97e7f7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -28,6 +28,22 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
28
  comfyui_path = os.path.join(current_dir, "ComfyUI")
29
  sys.path.append(comfyui_path)
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  from nodes import NODE_CLASS_MAPPINGS
32
  from comfy import model_management
33
  import folder_paths
@@ -47,6 +63,7 @@ def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
47
 
48
  # Baixar modelos necessários
49
  def download_models():
 
50
  models = [
51
  ("black-forest-labs/FLUX.1-Redux-dev", "flux1-redux-dev.safetensors", "models/style_models"),
52
  ("comfyanonymous/flux_text_encoders", "t5xxl_fp16.safetensors", "models/text_encoders"),
@@ -60,6 +77,9 @@ def download_models():
60
  for repo_id, filename, local_dir in models:
61
  hf_hub_download(repo_id=repo_id, filename=filename, local_dir=local_dir)
62
 
 
 
 
63
  # Inicializar modelos
64
  print("Inicializando modelos...")
65
  with torch.inference_mode():
@@ -87,22 +107,9 @@ with torch.inference_mode():
87
  ]
88
  model_management.load_models_gpu(valid_models)
89
 
90
- def import_custom_nodes():
91
- import asyncio
92
- import execution
93
- from nodes import init_extra_nodes
94
- import server
95
-
96
- loop = asyncio.new_event_loop()
97
- asyncio.set_event_loop(loop)
98
- server_instance = server.PromptServer(loop)
99
- execution.PromptQueue(server_instance)
100
- init_extra_nodes()
101
-
102
  @spaces.GPU
103
  def generate_image(prompt, input_image, lora_weight, progress=gr.Progress(track_tqdm=True)):
104
  """Função principal de geração com monitoramento de progresso"""
105
- import_custom_nodes()
106
  try:
107
  with torch.inference_mode():
108
  # Codificar texto
@@ -161,7 +168,4 @@ with gr.Blocks() as app:
161
  )
162
 
163
  if __name__ == "__main__":
164
- # Download models at startup
165
- download_models()
166
- # Launch the app
167
  app.launch()
 
28
  comfyui_path = os.path.join(current_dir, "ComfyUI")
29
  sys.path.append(comfyui_path)
30
 
31
+ # Import custom nodes primeiro
32
+ def import_custom_nodes():
33
+ import asyncio
34
+ import execution
35
+ from nodes import init_extra_nodes
36
+ import server
37
+
38
+ loop = asyncio.new_event_loop()
39
+ asyncio.set_event_loop(loop)
40
+ server_instance = server.PromptServer(loop)
41
+ execution.PromptQueue(server_instance)
42
+ init_extra_nodes()
43
+
44
+ print("Importando nós customizados...")
45
+ import_custom_nodes()
46
+
47
  from nodes import NODE_CLASS_MAPPINGS
48
  from comfy import model_management
49
  import folder_paths
 
63
 
64
  # Baixar modelos necessários
65
  def download_models():
66
+ print("Baixando modelos...")
67
  models = [
68
  ("black-forest-labs/FLUX.1-Redux-dev", "flux1-redux-dev.safetensors", "models/style_models"),
69
  ("comfyanonymous/flux_text_encoders", "t5xxl_fp16.safetensors", "models/text_encoders"),
 
77
  for repo_id, filename, local_dir in models:
78
  hf_hub_download(repo_id=repo_id, filename=filename, local_dir=local_dir)
79
 
80
+ # Download models antes de inicializar
81
+ download_models()
82
+
83
  # Inicializar modelos
84
  print("Inicializando modelos...")
85
  with torch.inference_mode():
 
107
  ]
108
  model_management.load_models_gpu(valid_models)
109
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  @spaces.GPU
111
  def generate_image(prompt, input_image, lora_weight, progress=gr.Progress(track_tqdm=True)):
112
  """Função principal de geração com monitoramento de progresso"""
 
113
  try:
114
  with torch.inference_mode():
115
  # Codificar texto
 
168
  )
169
 
170
  if __name__ == "__main__":
 
 
 
171
  app.launch()