Spaces:
Paused
Paused
Update setup.py
Browse files
setup.py
CHANGED
|
@@ -2,9 +2,9 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Versão 3.
|
| 6 |
# - Orquestra a instalação de todos os repositórios e modelos para a suíte ADUC-SDR.
|
| 7 |
-
# -
|
| 8 |
|
| 9 |
import os
|
| 10 |
import subprocess
|
|
@@ -13,12 +13,14 @@ from pathlib import Path
|
|
| 13 |
import yaml
|
| 14 |
from huggingface_hub import hf_hub_download, snapshot_download
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
#
|
|
|
|
|
|
|
| 18 |
DEPS_DIR = Path("/data")
|
| 19 |
CACHE_DIR = DEPS_DIR / ".cache" / "huggingface"
|
| 20 |
|
| 21 |
-
# ---
|
| 22 |
LTX_VIDEO_REPO_DIR = DEPS_DIR / "LTX-Video"
|
| 23 |
SEEDVR_MODELS_DIR = DEPS_DIR / "models" / "SeedVR"
|
| 24 |
VINCIE_REPO_DIR = DEPS_DIR / "VINCIE"
|
|
@@ -31,65 +33,69 @@ REPOS_TO_CLONE = {
|
|
| 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 |
-
|
| 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
|
| 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
|
| 69 |
-
"""Função
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
local_dir=str(local_dir) if local_dir else None,
|
| 80 |
-
|
| 81 |
token=os.getenv("HF_TOKEN"),
|
| 82 |
)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
def main():
|
| 92 |
-
"""
|
| 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)
|
|
@@ -105,28 +111,31 @@ def main():
|
|
| 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
|
| 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 |
-
|
| 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 |
-
|
| 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,
|
| 127 |
-
|
| 128 |
|
| 129 |
-
# --- ETAPA 3: Baixar Modelos
|
| 130 |
print("\n--- ETAPA 3: Verificando Modelos SeedVR ---")
|
| 131 |
SEEDVR_MODELS_DIR.mkdir(parents=True, exist_ok=True)
|
| 132 |
seedvr_files = {
|
|
@@ -136,38 +145,24 @@ def main():
|
|
| 136 |
}
|
| 137 |
for filename, repo_id in seedvr_files.items():
|
| 138 |
if not (SEEDVR_MODELS_DIR / filename).is_file():
|
| 139 |
-
|
| 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 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
print("->
|
| 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.")
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Versão 3.1.0 (Setup Unificado com LTX, SeedVR e VINCIE com Cache Robusto)
|
| 6 |
# - Orquestra a instalação de todos os repositórios e modelos para a suíte ADUC-SDR.
|
| 7 |
+
# - Usa snapshot_download para baixar dependências de forma eficiente e correta.
|
| 8 |
|
| 9 |
import os
|
| 10 |
import subprocess
|
|
|
|
| 13 |
import yaml
|
| 14 |
from huggingface_hub import hf_hub_download, snapshot_download
|
| 15 |
|
| 16 |
+
# ==============================================================================
|
| 17 |
+
# --- CONFIGURAÇÃO DE PATHS E CACHE ---
|
| 18 |
+
# ==============================================================================
|
| 19 |
+
# Assume que /data é um volume persistente montado no contêiner.
|
| 20 |
DEPS_DIR = Path("/data")
|
| 21 |
CACHE_DIR = DEPS_DIR / ".cache" / "huggingface"
|
| 22 |
|
| 23 |
+
# --- Paths dos Módulos da Aplicação ---
|
| 24 |
LTX_VIDEO_REPO_DIR = DEPS_DIR / "LTX-Video"
|
| 25 |
SEEDVR_MODELS_DIR = DEPS_DIR / "models" / "SeedVR"
|
| 26 |
VINCIE_REPO_DIR = DEPS_DIR / "VINCIE"
|
|
|
|
| 33 |
"VINCIE": "https://github.com/ByteDance-Seed/VINCIE",
|
| 34 |
}
|
| 35 |
|
| 36 |
+
# ==============================================================================
|
| 37 |
+
# --- FUNÇÕES AUXILIARES ---
|
| 38 |
+
# ==============================================================================
|
| 39 |
+
|
| 40 |
def run_command(command, cwd=None):
|
| 41 |
"""Executa um comando no terminal de forma segura e com logs claros."""
|
| 42 |
print(f"Executando: {' '.join(command)}")
|
| 43 |
try:
|
|
|
|
| 44 |
subprocess.run(
|
| 45 |
+
command, check=True, cwd=cwd,
|
| 46 |
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
except subprocess.CalledProcessError as e:
|
| 49 |
+
print(f"ERRO: O comando falhou com o código {e.returncode}\nStderr:\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.")
|
| 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 |
if not config_file.exists():
|
| 60 |
print(f"ERRO: Arquivo de configuração do LTX não encontrado em '{config_file}'")
|
| 61 |
return None
|
|
|
|
| 62 |
print(f"Configuração LTX encontrada: {config_file}")
|
| 63 |
with open(config_file, "r") as file:
|
| 64 |
return yaml.safe_load(file)
|
| 65 |
|
| 66 |
+
def _ensure_hf_model(repo_id, filenames=None, allow_patterns=None, local_dir=None):
|
| 67 |
+
"""Função genérica para baixar um ou mais arquivos (hf_hub_download) ou um snapshot (snapshot_download)."""
|
| 68 |
+
if not repo_id: return
|
| 69 |
+
|
| 70 |
+
print(f"Verificando/Baixando modelo do repositório: '{repo_id}'...")
|
| 71 |
+
try:
|
| 72 |
+
if filenames: # Baixa arquivos específicos
|
| 73 |
+
for filename in filenames:
|
| 74 |
+
if not filename: continue
|
| 75 |
+
hf_hub_download(
|
| 76 |
+
repo_id=repo_id, filename=filename, cache_dir=str(CACHE_DIR),
|
| 77 |
+
local_dir=str(local_dir) if local_dir else None,
|
| 78 |
+
#local_dir_use_symlinks=False,
|
| 79 |
+
token=os.getenv("HF_TOKEN"),
|
| 80 |
+
)
|
| 81 |
+
else: # Baixa um snapshot (partes de um repositório)
|
| 82 |
+
snapshot_download(
|
| 83 |
+
repo_id=repo_id, cache_dir=str(CACHE_DIR),
|
| 84 |
local_dir=str(local_dir) if local_dir else None,
|
| 85 |
+
allow_patterns=allow_patterns,
|
| 86 |
token=os.getenv("HF_TOKEN"),
|
| 87 |
)
|
| 88 |
+
print(f"-> Modelo '{repo_id}' está disponível.")
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"ERRO CRÍTICO ao baixar o modelo '{repo_id}': {e}")
|
| 91 |
+
sys.exit(1)
|
| 92 |
+
|
| 93 |
+
# ==============================================================================
|
| 94 |
+
# --- FUNÇÃO PRINCIPAL DE SETUP ---
|
| 95 |
+
# ==============================================================================
|
| 96 |
|
| 97 |
def main():
|
| 98 |
+
"""Orquestra todo o processo de setup do ambiente."""
|
| 99 |
print("--- Iniciando Setup do Ambiente ADUC-SDR (LTX + SeedVR + VINCIE) ---")
|
| 100 |
DEPS_DIR.mkdir(exist_ok=True)
|
| 101 |
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 111 |
run_command(["git", "clone", "--depth", "1", repo_url, str(repo_path)])
|
| 112 |
print(f"-> '{repo_name}' clonado com sucesso.")
|
| 113 |
|
| 114 |
+
# --- ETAPA 2: Baixar Modelos LTX-Video e Dependências ---
|
| 115 |
print("\n--- ETAPA 2: Verificando Modelos LTX-Video e Dependências ---")
|
| 116 |
ltx_config = _load_ltx_config()
|
| 117 |
if not ltx_config:
|
| 118 |
print("ERRO: Não foi possível carregar a configuração do LTX-Video. Abortando.")
|
| 119 |
sys.exit(1)
|
| 120 |
|
| 121 |
+
_ensure_hf_model(
|
| 122 |
repo_id="Lightricks/LTX-Video",
|
| 123 |
+
filenames=[ltx_config.get("checkpoint_path"), ltx_config.get("spatial_upscaler_model_path")]
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
+
_ensure_hf_model(
|
| 127 |
+
repo_id=ltx_config.get("text_encoder_model_name_or_path"),
|
| 128 |
+
allow_patterns=["*.json", "*.safetensors"]
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
enhancer_repos = [
|
| 132 |
ltx_config.get("prompt_enhancer_image_caption_model_name_or_path"),
|
| 133 |
ltx_config.get("prompt_enhancer_llm_model_name_or_path"),
|
| 134 |
]
|
| 135 |
+
for repo_id in filter(None, enhancer_repos):
|
| 136 |
+
_ensure_hf_model(repo_id=repo_id, allow_patterns=["*.json", "*.safetensors", "*.bin"])
|
| 137 |
|
| 138 |
+
# --- ETAPA 3: Baixar Modelos SeedVR ---
|
| 139 |
print("\n--- ETAPA 3: Verificando Modelos SeedVR ---")
|
| 140 |
SEEDVR_MODELS_DIR.mkdir(parents=True, exist_ok=True)
|
| 141 |
seedvr_files = {
|
|
|
|
| 145 |
}
|
| 146 |
for filename, repo_id in seedvr_files.items():
|
| 147 |
if not (SEEDVR_MODELS_DIR / filename).is_file():
|
| 148 |
+
_ensure_hf_model(repo_id=repo_id, filenames=[filename], local_dir=SEEDVR_MODELS_DIR)
|
| 149 |
else:
|
| 150 |
print(f"Arquivo SeedVR '{filename}' já existe. Pulando.")
|
| 151 |
|
| 152 |
# --- ETAPA 4: Baixar Modelos VINCIE ---
|
| 153 |
print("\n--- ETAPA 4: Verificando Modelos VINCIE ---")
|
| 154 |
VINCIE_CKPT_DIR.mkdir(parents=True, exist_ok=True)
|
| 155 |
+
_ensure_hf_model(repo_id="ByteDance-Seed/VINCIE-3B", local_dir=VINCIE_CKPT_DIR)
|
| 156 |
+
|
| 157 |
+
# Cria o symlink de compatibilidade, se necessário
|
| 158 |
+
repo_ckpt_dir = VINCIE_REPO_DIR / "ckpt"
|
| 159 |
+
repo_ckpt_dir.mkdir(parents=True, exist_ok=True)
|
| 160 |
+
link = repo_ckpt_dir / "VINCIE-3B"
|
| 161 |
+
if not link.exists():
|
| 162 |
+
link.symlink_to(VINCIE_CKPT_DIR.resolve(), target_is_directory=True)
|
| 163 |
+
print(f"-> Symlink de compatibilidade VINCIE criado: '{link}' -> '{VINCIE_CKPT_DIR.resolve()}'")
|
| 164 |
+
else:
|
| 165 |
+
print(f"-> Symlink de compatibilidade VINCIE já existe.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
print("\n\n--- ✅ Setup Completo do Ambiente ADUC-SDR Concluído com Sucesso! ---")
|
| 168 |
print("Todos os repositórios e modelos foram verificados e estão prontos para uso.")
|