Update aduc_framework/managers/seedvr_manager.py
Browse files
aduc_framework/managers/seedvr_manager.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
# hd_specialist.py (Versão Final - Estrutura de Arquivos Corrigida)
|
| 2 |
-
#https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B
|
| 3 |
|
| 4 |
import torch
|
| 5 |
import imageio
|
|
@@ -18,6 +18,7 @@ from omegaconf import OmegaConf
|
|
| 18 |
import sys
|
| 19 |
|
| 20 |
|
|
|
|
| 21 |
logger = logging.getLogger(__name__)
|
| 22 |
|
| 23 |
APP_ROOT = Path("/home/user/app")
|
|
@@ -109,19 +110,16 @@ class SeedVrManager:
|
|
| 109 |
ckpt_dir.mkdir(exist_ok=True)
|
| 110 |
|
| 111 |
pretrain_model_url = {
|
| 112 |
-
'configs_3b': 'https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B/tree/main/configs_3b/main.yaml',
|
| 113 |
'vae': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/ema_vae.pth',
|
| 114 |
'dit': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth',
|
| 115 |
'pos_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt',
|
| 116 |
'neg_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt'
|
| 117 |
}
|
| 118 |
-
|
| 119 |
-
_load_file_from_url(url=pretrain_model_url['configs_3b'], model_dir='./ckpts/')
|
| 120 |
_load_file_from_url(url=pretrain_model_url['dit'], model_dir='./ckpts/')
|
| 121 |
_load_file_from_url(url=pretrain_model_url['vae'], model_dir='./ckpts/')
|
| 122 |
_load_file_from_url(url=pretrain_model_url['pos_emb'])
|
| 123 |
_load_file_from_url(url=pretrain_model_url['neg_emb'])
|
| 124 |
-
|
| 125 |
logger.info("Modelos do SeedVR2 baixados com sucesso.")
|
| 126 |
|
| 127 |
def _initialize_runner(self):
|
|
@@ -133,8 +131,27 @@ class SeedVrManager:
|
|
| 133 |
self._download_models()
|
| 134 |
|
| 135 |
logger.info("Inicializando o runner do SeedVR2...")
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
self.runner = VideoDiffusionInfer(config)
|
| 140 |
OmegaConf.set_readonly(self.runner.config, False)
|
|
@@ -161,7 +178,7 @@ class SeedVrManager:
|
|
| 161 |
|
| 162 |
|
| 163 |
def process_video(self, input_video_path: str, output_video_path: str, prompt: str,
|
| 164 |
-
|
| 165 |
"""
|
| 166 |
Aplica o aprimoramento HD a um vídeo usando a lógica oficial do SeedVR.
|
| 167 |
"""
|
|
@@ -232,5 +249,5 @@ class SeedVrManager:
|
|
| 232 |
finally:
|
| 233 |
self._unload_runner()
|
| 234 |
|
| 235 |
-
# Instância Singleton
|
| 236 |
-
seedvr_manager_singleton = SeedVrManager()
|
|
|
|
| 1 |
+
# hd_specialist.py (Versão Final - Estrutura de Arquivos Corrigida e Autossuficiente)
|
| 2 |
+
# https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B
|
| 3 |
|
| 4 |
import torch
|
| 5 |
import imageio
|
|
|
|
| 18 |
import sys
|
| 19 |
|
| 20 |
|
| 21 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
| 24 |
APP_ROOT = Path("/home/user/app")
|
|
|
|
| 110 |
ckpt_dir.mkdir(exist_ok=True)
|
| 111 |
|
| 112 |
pretrain_model_url = {
|
|
|
|
| 113 |
'vae': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/ema_vae.pth',
|
| 114 |
'dit': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth',
|
| 115 |
'pos_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt',
|
| 116 |
'neg_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt'
|
| 117 |
}
|
| 118 |
+
|
|
|
|
| 119 |
_load_file_from_url(url=pretrain_model_url['dit'], model_dir='./ckpts/')
|
| 120 |
_load_file_from_url(url=pretrain_model_url['vae'], model_dir='./ckpts/')
|
| 121 |
_load_file_from_url(url=pretrain_model_url['pos_emb'])
|
| 122 |
_load_file_from_url(url=pretrain_model_url['neg_emb'])
|
|
|
|
| 123 |
logger.info("Modelos do SeedVR2 baixados com sucesso.")
|
| 124 |
|
| 125 |
def _initialize_runner(self):
|
|
|
|
| 131 |
self._download_models()
|
| 132 |
|
| 133 |
logger.info("Inicializando o runner do SeedVR2...")
|
| 134 |
+
|
| 135 |
+
# --- NOVO: Verificação e download automático do main.yaml ---
|
| 136 |
+
config_dir = Path('./configs_3b')
|
| 137 |
+
config_path = config_dir / 'main.yaml'
|
| 138 |
+
config_url = "https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B/resolve/main/configs_3b/main.yaml"
|
| 139 |
+
|
| 140 |
+
if not config_path.is_file():
|
| 141 |
+
logger.warning(f"Arquivo de configuração '{config_path}' não encontrado.")
|
| 142 |
+
logger.info("Tentando baixar automaticamente...")
|
| 143 |
+
try:
|
| 144 |
+
# Reutiliza a função de download existente
|
| 145 |
+
_load_file_from_url(url=config_url, model_dir=str(config_dir), file_name='main.yaml')
|
| 146 |
+
logger.info(f"✅ Arquivo de configuração baixado com sucesso para '{config_path}'")
|
| 147 |
+
except Exception as e:
|
| 148 |
+
logger.error(f"Falha ao baixar o arquivo de configuração. Por favor, baixe-o manualmente de {config_url} e coloque-o em {config_dir}. Erro: {e}")
|
| 149 |
+
raise
|
| 150 |
+
else:
|
| 151 |
+
logger.info(f"Arquivo de configuração encontrado em '{config_path}'.")
|
| 152 |
+
# --- FIM DA MODIFICAÇÃO ---
|
| 153 |
+
|
| 154 |
+
config = load_config(str(config_path))
|
| 155 |
|
| 156 |
self.runner = VideoDiffusionInfer(config)
|
| 157 |
OmegaConf.set_readonly(self.runner.config, False)
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
def process_video(self, input_video_path: str, output_video_path: str, prompt: str,
|
| 181 |
+
seed: int = 42, fps_out: int = 30) -> str:
|
| 182 |
"""
|
| 183 |
Aplica o aprimoramento HD a um vídeo usando a lógica oficial do SeedVR.
|
| 184 |
"""
|
|
|
|
| 249 |
finally:
|
| 250 |
self._unload_runner()
|
| 251 |
|
| 252 |
+
# Instância Singleton para facilitar o uso (opcional)
|
| 253 |
+
# seedvr_manager_singleton = SeedVrManager()
|