Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,17 +32,17 @@ print(f"Diretório de trabalho alterado para: {os.getcwd()}")
|
|
| 32 |
sys.path.insert(0, os.path.abspath('.'))
|
| 33 |
print(f"Diretório atual adicionado ao sys.path para importações.")
|
| 34 |
|
| 35 |
-
# --- ETAPA 3: Instalação de Dependências (NA ORDEM CORRETA) ---
|
| 36 |
|
| 37 |
python_executable = sys.executable
|
| 38 |
|
| 39 |
-
# **
|
| 40 |
print("Instalando dependências a partir do requirements.txt (isso inclui o PyTorch)...")
|
| 41 |
subprocess.run([python_executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
|
| 42 |
print("✅ Dependências básicas (incluindo PyTorch) instaladas.")
|
| 43 |
|
| 44 |
|
| 45 |
-
# **Compilar dependências otimizadas para a GPU
|
| 46 |
print("Instalando flash-attn compilando do zero...")
|
| 47 |
subprocess.run([python_executable, "-m", "pip", "install", "--force-reinstall", "--no-cache-dir", "flash-attn"], check=True)
|
| 48 |
|
|
@@ -50,16 +50,27 @@ print("Clonando e compilando o Apex do zero (isso pode demorar um pouco)...")
|
|
| 50 |
if not os.path.exists("apex"):
|
| 51 |
subprocess.run("git clone https://github.com/NVIDIA/apex", shell=True, check=True)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
#
|
|
|
|
|
|
|
| 55 |
subprocess.run(
|
| 56 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
check=True
|
| 58 |
)
|
| 59 |
print("✅ Configuração do Apex concluída.")
|
| 60 |
|
| 61 |
|
| 62 |
-
# **Download dos modelos e dados de exemplo**
|
| 63 |
import torch
|
| 64 |
from pathlib import Path
|
| 65 |
from urllib.parse import urlparse
|
|
@@ -67,11 +78,9 @@ from torch.hub import download_url_to_file, get_dir
|
|
| 67 |
|
| 68 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 69 |
if model_dir is None:
|
| 70 |
-
hub_dir = get_dir()
|
| 71 |
-
model_dir = os.path.join(hub_dir, 'checkpoints')
|
| 72 |
os.makedirs(model_dir, exist_ok=True)
|
| 73 |
-
parts = urlparse(url)
|
| 74 |
-
filename = os.path.basename(parts.path)
|
| 75 |
if file_name is not None: filename = file_name
|
| 76 |
cached_file = os.path.abspath(os.path.join(model_dir, filename))
|
| 77 |
if not os.path.exists(cached_file):
|
|
@@ -90,8 +99,7 @@ ckpt_dir = Path('./ckpts'); ckpt_dir.mkdir(exist_ok=True)
|
|
| 90 |
for key, url in pretrain_model_url.items():
|
| 91 |
filename = os.path.basename(url)
|
| 92 |
model_dir = './ckpts' if key in ['vae', 'dit'] else '.'
|
| 93 |
-
|
| 94 |
-
if not os.path.exists(target_path):
|
| 95 |
load_file_from_url(url=url, model_dir=model_dir, progress=True, file_name=filename)
|
| 96 |
|
| 97 |
torch.hub.download_url_to_file('https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/23_1_lq.mp4', '01.mp4')
|
|
|
|
| 32 |
sys.path.insert(0, os.path.abspath('.'))
|
| 33 |
print(f"Diretório atual adicionado ao sys.path para importações.")
|
| 34 |
|
| 35 |
+
# --- ETAPA 3: Instalação de Dependências (NA ORDEM CORRETA E COM A FLAG CORRETA) ---
|
| 36 |
|
| 37 |
python_executable = sys.executable
|
| 38 |
|
| 39 |
+
# **PASSO 3.1: Instalar requisitos PRIMEIRO para ter o PyTorch disponível**
|
| 40 |
print("Instalando dependências a partir do requirements.txt (isso inclui o PyTorch)...")
|
| 41 |
subprocess.run([python_executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
|
| 42 |
print("✅ Dependências básicas (incluindo PyTorch) instaladas.")
|
| 43 |
|
| 44 |
|
| 45 |
+
# **PASSO 3.2: Compilar dependências otimizadas para a GPU**
|
| 46 |
print("Instalando flash-attn compilando do zero...")
|
| 47 |
subprocess.run([python_executable, "-m", "pip", "install", "--force-reinstall", "--no-cache-dir", "flash-attn"], check=True)
|
| 48 |
|
|
|
|
| 50 |
if not os.path.exists("apex"):
|
| 51 |
subprocess.run("git clone https://github.com/NVIDIA/apex", shell=True, check=True)
|
| 52 |
|
| 53 |
+
# **CORREÇÃO FINAL: Adicionar a flag --no-build-isolation**
|
| 54 |
+
# Isso força o build a usar o ambiente atual (onde o torch já foi instalado)
|
| 55 |
+
# em vez de criar um ambiente isolado e vazio.
|
| 56 |
+
print("Compilando e instalando o Apex...")
|
| 57 |
subprocess.run(
|
| 58 |
+
[
|
| 59 |
+
python_executable, "-m", "pip", "install",
|
| 60 |
+
"--no-build-isolation", # A FLAG CRÍTICA QUE RESOLVE O PROBLEMA
|
| 61 |
+
"-v",
|
| 62 |
+
"--disable-pip-version-check",
|
| 63 |
+
"--no-cache-dir",
|
| 64 |
+
"--global-option=--cpp_ext",
|
| 65 |
+
"--global-option=--cuda_ext",
|
| 66 |
+
"./apex"
|
| 67 |
+
],
|
| 68 |
check=True
|
| 69 |
)
|
| 70 |
print("✅ Configuração do Apex concluída.")
|
| 71 |
|
| 72 |
|
| 73 |
+
# **PASSO 3.3: Download dos modelos e dados de exemplo**
|
| 74 |
import torch
|
| 75 |
from pathlib import Path
|
| 76 |
from urllib.parse import urlparse
|
|
|
|
| 78 |
|
| 79 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 80 |
if model_dir is None:
|
| 81 |
+
hub_dir = get_dir(); model_dir = os.path.join(hub_dir, 'checkpoints')
|
|
|
|
| 82 |
os.makedirs(model_dir, exist_ok=True)
|
| 83 |
+
parts = urlparse(url); filename = os.path.basename(parts.path)
|
|
|
|
| 84 |
if file_name is not None: filename = file_name
|
| 85 |
cached_file = os.path.abspath(os.path.join(model_dir, filename))
|
| 86 |
if not os.path.exists(cached_file):
|
|
|
|
| 99 |
for key, url in pretrain_model_url.items():
|
| 100 |
filename = os.path.basename(url)
|
| 101 |
model_dir = './ckpts' if key in ['vae', 'dit'] else '.'
|
| 102 |
+
if not os.path.exists(os.path.join(model_dir, filename)):
|
|
|
|
| 103 |
load_file_from_url(url=url, model_dir=model_dir, progress=True, file_name=filename)
|
| 104 |
|
| 105 |
torch.hub.download_url_to_file('https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/23_1_lq.mp4', '01.mp4')
|