Spaces:
Paused
Paused
Update setup.py
Browse files
setup.py
CHANGED
|
@@ -2,179 +2,175 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Versão
|
| 6 |
-
# -
|
| 7 |
-
# -
|
| 8 |
-
# - Unifica o download de todas as dependências (Git, LTX Models, SeedVR Models).
|
| 9 |
|
| 10 |
import os
|
| 11 |
import subprocess
|
| 12 |
import sys
|
| 13 |
from pathlib import Path
|
| 14 |
import yaml
|
| 15 |
-
from huggingface_hub import hf_hub_download
|
| 16 |
|
| 17 |
-
# --- Configuração
|
|
|
|
| 18 |
DEPS_DIR = Path("/data")
|
|
|
|
| 19 |
|
| 20 |
-
# --- Configuração
|
| 21 |
LTX_VIDEO_REPO_DIR = DEPS_DIR / "LTX-Video"
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# ---
|
| 24 |
-
SEEDVR_MODELS_DIR = DEPS_DIR / "SeedVR"
|
| 25 |
-
|
| 26 |
-
# --- Repositórios para Clonar ---
|
| 27 |
REPOS_TO_CLONE = {
|
| 28 |
"LTX-Video": "https://huggingface.co/spaces/Lightricks/ltx-video-distilled",
|
| 29 |
"SeedVR": "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler",
|
| 30 |
-
"
|
| 31 |
}
|
| 32 |
|
| 33 |
def run_command(command, cwd=None):
|
| 34 |
-
"""Executa um comando no terminal e
|
| 35 |
print(f"Executando: {' '.join(command)}")
|
| 36 |
try:
|
|
|
|
| 37 |
subprocess.run(
|
| 38 |
command,
|
| 39 |
check=True,
|
| 40 |
cwd=cwd,
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
except subprocess.CalledProcessError as e:
|
| 44 |
-
print(f"ERRO: O comando falhou com o código
|
|
|
|
| 45 |
sys.exit(1)
|
| 46 |
except FileNotFoundError:
|
| 47 |
-
print(f"ERRO:
|
| 48 |
sys.exit(1)
|
| 49 |
|
| 50 |
-
# --- Funções de Download (LTX-Video) ---
|
| 51 |
-
|
| 52 |
def _load_ltx_config():
|
| 53 |
"""Carrega o arquivo de configuração YAML do LTX-Video."""
|
| 54 |
print("--- Carregando Configuração do LTX-Video ---")
|
| 55 |
-
|
| 56 |
-
candidates = [
|
| 57 |
-
base / "ltxv-13b-0.9.8-dev-fp8.yaml",
|
| 58 |
-
base / "ltxv-13b-0.9.8-distilled-fp8.yaml",
|
| 59 |
-
base / "ltxv-13b-0.9.8-distilled.yaml",
|
| 60 |
-
]
|
| 61 |
-
for cfg_path in candidates:
|
| 62 |
-
if cfg_path.exists():
|
| 63 |
-
print(f"Configuração encontrada: {cfg_path}")
|
| 64 |
-
with open(cfg_path, "r") as file:
|
| 65 |
-
return yaml.safe_load(file)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
if not fallback_path.exists():
|
| 70 |
-
print(f"ERRO: Arquivo de configuração fallback '{fallback_path}' não encontrado.")
|
| 71 |
return None
|
| 72 |
|
| 73 |
-
|
|
|
|
| 74 |
return yaml.safe_load(file)
|
| 75 |
|
| 76 |
-
def
|
| 77 |
-
"""
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
print("ERRO: Chaves de modelo não encontradas no arquivo de configuração do LTX.")
|
| 83 |
-
sys.exit(1)
|
| 84 |
-
|
| 85 |
-
models_to_download = {
|
| 86 |
-
config["checkpoint_path"]: "checkpoint principal",
|
| 87 |
-
config["spatial_upscaler_model_path"]: "upscaler espacial"
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
# O hf_hub_download já verifica o cache, mas vamos verificar o diretório final para clareza
|
| 91 |
-
# e para garantir que a lógica seja explícita.
|
| 92 |
-
for filename, description in models_to_download.items():
|
| 93 |
-
# A biblioteca huggingface_hub gerencia o local exato, então confiamos nela.
|
| 94 |
-
# A verificação aqui é para garantir que o download seja tentado.
|
| 95 |
-
print(f"Garantindo a existência do {description}: {filename}...")
|
| 96 |
try:
|
| 97 |
hf_hub_download(
|
| 98 |
-
repo_id=
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
)
|
| 101 |
-
print(f"{
|
| 102 |
except Exception as e:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
def _download_seedvr_models():
|
| 108 |
-
"""Baixa os modelos do SeedVR, pulando os que já existem."""
|
| 109 |
-
print(f"\n--- Verificando Checkpoints do SeedVR em {SEEDVR_MODELS_DIR} ---")
|
| 110 |
-
SEEDVR_MODELS_DIR.mkdir(exist_ok=True)
|
| 111 |
-
|
| 112 |
-
model_files = {
|
| 113 |
-
"seedvr2_ema_7b_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 114 |
-
"seedvr2_ema_7b_sharp_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 115 |
-
"seedvr2_ema_3b_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 116 |
-
"ema_vae_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 117 |
-
"pos_emb.pt": "ByteDance-Seed/SeedVR2-3B",
|
| 118 |
-
"neg_emb.pt": "ByteDance-Seed/SeedVR2-3B"
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
for filename, repo_id in model_files.items():
|
| 122 |
-
local_path = SEEDVR_MODELS_DIR / filename
|
| 123 |
-
if not local_path.is_file(): # Verifica se é um arquivo
|
| 124 |
-
print(f"Baixando {filename} de {repo_id}...")
|
| 125 |
-
try:
|
| 126 |
-
hf_hub_download(
|
| 127 |
-
repo_id=repo_id,
|
| 128 |
-
filename=filename,
|
| 129 |
-
local_dir=str(SEEDVR_MODELS_DIR),
|
| 130 |
-
cache_dir=os.getenv("HF_HOME_CACHE"),
|
| 131 |
-
token=os.getenv("HF_TOKEN"),
|
| 132 |
-
)
|
| 133 |
-
print(f"'{filename}' baixado com sucesso.")
|
| 134 |
-
except Exception as e:
|
| 135 |
-
print(f"ERRO ao baixar o modelo SeedVR '{filename}': {e}")
|
| 136 |
sys.exit(1)
|
| 137 |
-
else:
|
| 138 |
-
print(f"Arquivo '{filename}' já existe. Pulando.")
|
| 139 |
-
print("Checkpoints do SeedVR estão no local correto.")
|
| 140 |
-
|
| 141 |
-
# --- Função Principal ---
|
| 142 |
|
| 143 |
def main():
|
| 144 |
-
|
|
|
|
| 145 |
DEPS_DIR.mkdir(exist_ok=True)
|
|
|
|
| 146 |
|
| 147 |
# --- ETAPA 1: Clonar Repositórios ---
|
| 148 |
-
print("\n--- ETAPA 1:
|
| 149 |
for repo_name, repo_url in REPOS_TO_CLONE.items():
|
| 150 |
repo_path = DEPS_DIR / repo_name
|
| 151 |
-
if repo_path.is_dir():
|
| 152 |
-
print(f"Repositório '{repo_name}' já existe. Pulando.")
|
| 153 |
else:
|
| 154 |
print(f"Clonando '{repo_name}' de {repo_url}...")
|
| 155 |
run_command(["git", "clone", "--depth", "1", repo_url, str(repo_path)])
|
| 156 |
-
print(f"'{repo_name}' clonado com sucesso.")
|
| 157 |
|
| 158 |
-
# --- ETAPA 2: Baixar Modelos do LTX-Video ---
|
| 159 |
-
print("\n--- ETAPA 2:
|
| 160 |
-
if not LTX_VIDEO_REPO_DIR.is_dir():
|
| 161 |
-
print(f"ERRO: Diretório '{LTX_VIDEO_REPO_DIR}' não encontrado. Execute a clonagem primeiro.")
|
| 162 |
-
sys.exit(1)
|
| 163 |
-
|
| 164 |
ltx_config = _load_ltx_config()
|
| 165 |
-
if ltx_config:
|
| 166 |
-
_download_ltx_models(ltx_config)
|
| 167 |
-
else:
|
| 168 |
print("ERRO: Não foi possível carregar a configuração do LTX-Video. Abortando.")
|
| 169 |
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# --- ETAPA 3: Baixar Modelos do SeedVR ---
|
| 172 |
-
print("\n--- ETAPA 3:
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
print("\n\n--- Setup do Ambiente Concluído com Sucesso! ---")
|
| 176 |
-
print("Todos os repositórios e modelos
|
| 177 |
-
print("Você agora pode iniciar a aplicação principal.")
|
| 178 |
|
| 179 |
if __name__ == "__main__":
|
| 180 |
main()
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Versão 3.0.0 (Setup Unificado com LTX, SeedVR e VINCIE)
|
| 6 |
+
# - Orquestra a instalação de todos os repositórios e modelos para a suíte ADUC-SDR.
|
| 7 |
+
# - Garante que todos os downloads usem um cache persistente para inicializações rápidas.
|
|
|
|
| 8 |
|
| 9 |
import os
|
| 10 |
import subprocess
|
| 11 |
import sys
|
| 12 |
from pathlib import Path
|
| 13 |
import yaml
|
| 14 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 15 |
|
| 16 |
+
# --- Configuração de Paths e Cache ---
|
| 17 |
+
# Assume-se que /data é um volume persistente montado no contêiner.
|
| 18 |
DEPS_DIR = Path("/data")
|
| 19 |
+
CACHE_DIR = DEPS_DIR / ".cache" / "huggingface"
|
| 20 |
|
| 21 |
+
# --- Configuração dos Módulos da Aplicação ---
|
| 22 |
LTX_VIDEO_REPO_DIR = DEPS_DIR / "LTX-Video"
|
| 23 |
+
SEEDVR_MODELS_DIR = DEPS_DIR / "models" / "SeedVR"
|
| 24 |
+
VINCIE_REPO_DIR = DEPS_DIR / "VINCIE"
|
| 25 |
+
VINCIE_CKPT_DIR = DEPS_DIR / "ckpt" / "VINCIE-3B"
|
| 26 |
|
| 27 |
+
# --- Repositórios Git para Clonar ---
|
|
|
|
|
|
|
|
|
|
| 28 |
REPOS_TO_CLONE = {
|
| 29 |
"LTX-Video": "https://huggingface.co/spaces/Lightricks/ltx-video-distilled",
|
| 30 |
"SeedVR": "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler",
|
| 31 |
+
"VINCIE": "https://github.com/ByteDance-Seed/VINCIE",
|
| 32 |
}
|
| 33 |
|
| 34 |
def run_command(command, cwd=None):
|
| 35 |
+
"""Executa um comando no terminal de forma segura e com logs claros."""
|
| 36 |
print(f"Executando: {' '.join(command)}")
|
| 37 |
try:
|
| 38 |
+
# Usamos check=True para lançar uma exceção se o comando falhar.
|
| 39 |
subprocess.run(
|
| 40 |
command,
|
| 41 |
check=True,
|
| 42 |
cwd=cwd,
|
| 43 |
+
stdout=subprocess.PIPE,
|
| 44 |
+
stderr=subprocess.PIPE,
|
| 45 |
+
text=True,
|
| 46 |
)
|
| 47 |
except subprocess.CalledProcessError as e:
|
| 48 |
+
print(f"ERRO: O comando falhou com o código {e.returncode}")
|
| 49 |
+
print(f"Stderr:\n{e.stderr.strip()}")
|
| 50 |
sys.exit(1)
|
| 51 |
except FileNotFoundError:
|
| 52 |
+
print(f"ERRO: Comando '{command[0]}' não encontrado. Verifique se o git está instalado no contêiner.")
|
| 53 |
sys.exit(1)
|
| 54 |
|
|
|
|
|
|
|
| 55 |
def _load_ltx_config():
|
| 56 |
"""Carrega o arquivo de configuração YAML do LTX-Video."""
|
| 57 |
print("--- Carregando Configuração do LTX-Video ---")
|
| 58 |
+
config_file = LTX_VIDEO_REPO_DIR / "configs" / "ltxv-13b-0.9.8-distilled-fp8.yaml"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
if not config_file.exists():
|
| 61 |
+
print(f"ERRO: Arquivo de configuração do LTX não encontrado em '{config_file}'")
|
|
|
|
|
|
|
| 62 |
return None
|
| 63 |
|
| 64 |
+
print(f"Configuração LTX encontrada: {config_file}")
|
| 65 |
+
with open(config_file, "r") as file:
|
| 66 |
return yaml.safe_load(file)
|
| 67 |
|
| 68 |
+
def _download_models_from_hub(repo_id, filenames, cache_dir, local_dir=None):
|
| 69 |
+
"""Função auxiliar genérica para baixar arquivos do Hugging Face Hub."""
|
| 70 |
+
for filename in filenames:
|
| 71 |
+
if not filename: continue
|
| 72 |
+
|
| 73 |
+
print(f"Verificando/Baixando '{filename}' de '{repo_id}'...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
try:
|
| 75 |
hf_hub_download(
|
| 76 |
+
repo_id=repo_id,
|
| 77 |
+
filename=filename,
|
| 78 |
+
cache_dir=str(cache_dir),
|
| 79 |
+
local_dir=str(local_dir) if local_dir else None,
|
| 80 |
+
local_dir_use_symlinks=False, # Salva o arquivo real, não um link simbólico
|
| 81 |
+
token=os.getenv("HF_TOKEN"),
|
| 82 |
)
|
| 83 |
+
print(f"-> '{filename}' está disponível.")
|
| 84 |
except Exception as e:
|
| 85 |
+
if "404" in str(e) or "Not Found" in str(e):
|
| 86 |
+
print(f"AVISO: Arquivo '{filename}' não encontrado em '{repo_id}'. Isso pode ser normal se for um ponteiro para um diretório (como em Text Encoders). Continuando.")
|
| 87 |
+
else:
|
| 88 |
+
print(f"ERRO CRÍTICO ao baixar '{filename}': {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
def main():
|
| 92 |
+
"""Função principal que orquestra todo o processo de setup."""
|
| 93 |
+
print("--- Iniciando Setup do Ambiente ADUC-SDR (LTX + SeedVR + VINCIE) ---")
|
| 94 |
DEPS_DIR.mkdir(exist_ok=True)
|
| 95 |
+
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
| 96 |
|
| 97 |
# --- ETAPA 1: Clonar Repositórios ---
|
| 98 |
+
print("\n--- ETAPA 1: Verificando Repositórios Git ---")
|
| 99 |
for repo_name, repo_url in REPOS_TO_CLONE.items():
|
| 100 |
repo_path = DEPS_DIR / repo_name
|
| 101 |
+
if repo_path.is_dir():
|
| 102 |
+
print(f"Repositório '{repo_name}' já existe em '{repo_path}'. Pulando.")
|
| 103 |
else:
|
| 104 |
print(f"Clonando '{repo_name}' de {repo_url}...")
|
| 105 |
run_command(["git", "clone", "--depth", "1", repo_url, str(repo_path)])
|
| 106 |
+
print(f"-> '{repo_name}' clonado com sucesso.")
|
| 107 |
|
| 108 |
+
# --- ETAPA 2: Baixar Modelos do LTX-Video e suas Dependências ---
|
| 109 |
+
print("\n--- ETAPA 2: Verificando Modelos LTX-Video e Dependências ---")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
ltx_config = _load_ltx_config()
|
| 111 |
+
if not ltx_config:
|
|
|
|
|
|
|
| 112 |
print("ERRO: Não foi possível carregar a configuração do LTX-Video. Abortando.")
|
| 113 |
sys.exit(1)
|
| 114 |
+
|
| 115 |
+
_download_models_from_hub(
|
| 116 |
+
repo_id="Lightricks/LTX-Video",
|
| 117 |
+
filenames=[ltx_config.get("checkpoint_path"), ltx_config.get("spatial_upscaler_model_path")],
|
| 118 |
+
cache_dir=CACHE_DIR
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
dependency_repos = [
|
| 122 |
+
ltx_config.get("text_encoder_model_name_or_path"),
|
| 123 |
+
ltx_config.get("prompt_enhancer_image_caption_model_name_or_path"),
|
| 124 |
+
ltx_config.get("prompt_enhancer_llm_model_name_or_path"),
|
| 125 |
+
]
|
| 126 |
+
for repo_id in filter(None, dependency_repos):
|
| 127 |
+
_download_models_from_hub(repo_id=repo_id, filenames=["config.json"], cache_dir=CACHE_DIR)
|
| 128 |
|
| 129 |
# --- ETAPA 3: Baixar Modelos do SeedVR ---
|
| 130 |
+
print("\n--- ETAPA 3: Verificando Modelos SeedVR ---")
|
| 131 |
+
SEEDVR_MODELS_DIR.mkdir(parents=True, exist_ok=True)
|
| 132 |
+
seedvr_files = {
|
| 133 |
+
"seedvr2_ema_7b_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 134 |
+
"seedvr2_ema_7b_sharp_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 135 |
+
"ema_vae_fp16.safetensors": "MonsterMMORPG/SeedVR2_SECourses",
|
| 136 |
+
}
|
| 137 |
+
for filename, repo_id in seedvr_files.items():
|
| 138 |
+
if not (SEEDVR_MODELS_DIR / filename).is_file():
|
| 139 |
+
_download_models_from_hub(repo_id=repo_id, filenames=[filename], cache_dir=CACHE_DIR, local_dir=SEEDVR_MODELS_DIR)
|
| 140 |
+
else:
|
| 141 |
+
print(f"Arquivo SeedVR '{filename}' já existe. Pulando.")
|
| 142 |
+
|
| 143 |
+
# --- ETAPA 4: Baixar Modelos VINCIE ---
|
| 144 |
+
print("\n--- ETAPA 4: Verificando Modelos VINCIE ---")
|
| 145 |
+
VINCIE_CKPT_DIR.mkdir(parents=True, exist_ok=True)
|
| 146 |
+
try:
|
| 147 |
+
print(f"Verificando snapshot do VINCIE em '{VINCIE_CKPT_DIR}'...")
|
| 148 |
+
# snapshot_download é ideal para baixar um repositório inteiro.
|
| 149 |
+
snapshot_download(
|
| 150 |
+
repo_id="ByteDance-Seed/VINCIE-3B",
|
| 151 |
+
local_dir=str(VINCIE_CKPT_DIR),
|
| 152 |
+
cache_dir=str(CACHE_DIR),
|
| 153 |
+
force_download=False, # Não baixa novamente se o diretório já estiver completo
|
| 154 |
+
token=os.getenv("HF_TOKEN")
|
| 155 |
+
)
|
| 156 |
+
print("-> Modelos VINCIE estão disponíveis.")
|
| 157 |
+
|
| 158 |
+
# Cria o symlink de compatibilidade, se necessário, para que o código do VINCIE encontre os modelos
|
| 159 |
+
repo_ckpt_dir = VINCIE_REPO_DIR / "ckpt"
|
| 160 |
+
repo_ckpt_dir.mkdir(parents=True, exist_ok=True)
|
| 161 |
+
link = repo_ckpt_dir / "VINCIE-3B"
|
| 162 |
+
if not link.exists():
|
| 163 |
+
link.symlink_to(VINCIE_CKPT_DIR.resolve(), target_is_directory=True)
|
| 164 |
+
print(f"-> Symlink de compatibilidade VINCIE criado: '{link}' -> '{VINCIE_CKPT_DIR.resolve()}'")
|
| 165 |
+
else:
|
| 166 |
+
print(f"-> Symlink de compatibilidade VINCIE já existe.")
|
| 167 |
+
|
| 168 |
+
except Exception as e:
|
| 169 |
+
print(f"ERRO CRÍTICO ao baixar modelos VINCIE: {e}")
|
| 170 |
+
sys.exit(1)
|
| 171 |
|
| 172 |
+
print("\n\n--- ✅ Setup Completo do Ambiente ADUC-SDR Concluído com Sucesso! ---")
|
| 173 |
+
print("Todos os repositórios e modelos foram verificados e estão prontos para uso.")
|
|
|
|
| 174 |
|
| 175 |
if __name__ == "__main__":
|
| 176 |
main()
|