Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,11 +32,14 @@ print(f"Diretório atual adicionado ao sys.path.")
|
|
| 32 |
# --- ETAPA 3: Instalar Dependências Corretamente ---
|
| 33 |
python_executable = sys.executable
|
| 34 |
|
| 35 |
-
# CORREÇÃO
|
| 36 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
with open("requirements.txt", "r") as f_in, open("filtered_requirements.txt", "w") as f_out:
|
| 38 |
for line in f_in:
|
| 39 |
-
# Ignora as linhas que podem causar conflitos
|
| 40 |
if not line.strip().startswith(('torch', 'torchvision')):
|
| 41 |
f_out.write(line)
|
| 42 |
|
|
@@ -104,26 +107,18 @@ from data.image.transforms.na_resize import NaResize
|
|
| 104 |
from data.video.transforms.rearrange import Rearrange
|
| 105 |
from common.config import load_config
|
| 106 |
from common.distributed import init_torch
|
| 107 |
-
from common.distributed.advanced import init_sequence_parallel
|
| 108 |
from common.seed import set_seed
|
| 109 |
-
from common.partition import partition_by_size
|
| 110 |
from projects.video_diffusion_sr.infer import VideoDiffusionInfer
|
| 111 |
from common.distributed.ops import sync_data
|
| 112 |
|
| 113 |
-
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')
|
| 114 |
-
torch.hub.download_url_to_file('https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/28_1_lq.mp4', '02.mp4')
|
| 115 |
-
torch.hub.download_url_to_file('https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/2_1_lq.mp4', '03.mp4')
|
| 116 |
-
print("✅ Setup completo. Iniciando a aplicação...")
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
os.environ["MASTER_ADDR"] = "127.0.0.1"
|
| 122 |
os.environ["MASTER_PORT"] = "12355"
|
| 123 |
os.environ["RANK"] = str(0)
|
| 124 |
os.environ["WORLD_SIZE"] = str(1)
|
| 125 |
|
| 126 |
use_colorfix = os.path.exists("projects/video_diffusion_sr/color_fix.py")
|
|
|
|
|
|
|
| 127 |
|
| 128 |
def configure_runner():
|
| 129 |
config = load_config('configs_3b/main.yaml')
|
|
@@ -155,11 +150,25 @@ def generation_step(runner, text_embeds_dict, cond_latents):
|
|
| 155 |
def generation_loop(video_path, seed=666, fps_out=24):
|
| 156 |
if video_path is None: return None, None, None
|
| 157 |
runner = configure_runner()
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
runner.configure_diffusion()
|
| 160 |
set_seed(int(seed))
|
| 161 |
os.makedirs("output", exist_ok=True)
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
media_type, _ = mimetypes.guess_type(video_path)
|
| 164 |
is_video = media_type and media_type.startswith("video")
|
| 165 |
|
|
@@ -187,9 +196,7 @@ def generation_loop(video_path, seed=666, fps_out=24):
|
|
| 187 |
|
| 188 |
with gr.Blocks(title="SeedVR") as demo:
|
| 189 |
gr.HTML(f"""
|
| 190 |
-
|
| 191 |
-
<img src='file/{os.path.abspath("assets/seedvr_logo.png")}' style='height:40px;' alt='SeedVR logo'/>
|
| 192 |
-
</div>
|
| 193 |
<p><b>Demonstração oficial do Gradio</b> para
|
| 194 |
<a href='https://github.com/ByteDance-Seed/SeedVR' target='_blank'>
|
| 195 |
<b>SeedVR2: One-Step Video Restoration via Diffusion Adversarial Post-Training</b></a>.<br>
|
|
@@ -206,11 +213,6 @@ with gr.Blocks(title="SeedVR") as demo:
|
|
| 206 |
output_video = gr.Video(label="Vídeo de Saída")
|
| 207 |
download_link = gr.File(label="Baixar Resultado")
|
| 208 |
run_button.click(fn=generation_loop, inputs=[input_file, seed, fps], outputs=[output_image, output_video, download_link])
|
| 209 |
-
|
| 210 |
-
gr.HTML("""
|
| 211 |
-
<hr>
|
| 212 |
-
<p>Se você achou o SeedVR útil, por favor ⭐ o
|
| 213 |
-
<a href='https://github.com/ByteDance-Seed/SeedVR' target='_blank'>repositório no GitHub</a>.</p>
|
| 214 |
-
""")
|
| 215 |
|
| 216 |
demo.queue().launch(share=True)
|
|
|
|
| 32 |
# --- ETAPA 3: Instalar Dependências Corretamente ---
|
| 33 |
python_executable = sys.executable
|
| 34 |
|
| 35 |
+
# CORREÇÃO: Forçar uma versão do NumPy < 2.0 para evitar conflitos de compatibilidade.
|
| 36 |
+
print("Instalando NumPy compatível...")
|
| 37 |
+
subprocess.run([python_executable, "-m", "pip", "install", "numpy<2.0"], check=True)
|
| 38 |
+
|
| 39 |
+
# Filtrar requirements.txt para evitar conflitos com torch/torchvision pré-instalados
|
| 40 |
+
print("Filtrando requirements.txt...")
|
| 41 |
with open("requirements.txt", "r") as f_in, open("filtered_requirements.txt", "w") as f_out:
|
| 42 |
for line in f_in:
|
|
|
|
| 43 |
if not line.strip().startswith(('torch', 'torchvision')):
|
| 44 |
f_out.write(line)
|
| 45 |
|
|
|
|
| 107 |
from data.video.transforms.rearrange import Rearrange
|
| 108 |
from common.config import load_config
|
| 109 |
from common.distributed import init_torch
|
|
|
|
| 110 |
from common.seed import set_seed
|
|
|
|
| 111 |
from projects.video_diffusion_sr.infer import VideoDiffusionInfer
|
| 112 |
from common.distributed.ops import sync_data
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
os.environ["MASTER_ADDR"] = "127.0.0.1"
|
| 115 |
os.environ["MASTER_PORT"] = "12355"
|
| 116 |
os.environ["RANK"] = str(0)
|
| 117 |
os.environ["WORLD_SIZE"] = str(1)
|
| 118 |
|
| 119 |
use_colorfix = os.path.exists("projects/video_diffusion_sr/color_fix.py")
|
| 120 |
+
if use_colorfix:
|
| 121 |
+
from projects.video_diffusion_sr.color_fix import wavelet_reconstruction
|
| 122 |
|
| 123 |
def configure_runner():
|
| 124 |
config = load_config('configs_3b/main.yaml')
|
|
|
|
| 150 |
def generation_loop(video_path, seed=666, fps_out=24):
|
| 151 |
if video_path is None: return None, None, None
|
| 152 |
runner = configure_runner()
|
| 153 |
+
# Adicionado `weights_only=True` para segurança e para suprimir o aviso
|
| 154 |
+
text_embeds = {
|
| 155 |
+
"texts_pos": [torch.load('pos_emb.pt', weights_only=True).to("cuda")],
|
| 156 |
+
"texts_neg": [torch.load('neg_emb.pt', weights_only=True).to("cuda")]
|
| 157 |
+
}
|
| 158 |
runner.configure_diffusion()
|
| 159 |
set_seed(int(seed))
|
| 160 |
os.makedirs("output", exist_ok=True)
|
| 161 |
+
|
| 162 |
+
# CORREÇÃO: Fornecer os argumentos que faltam para NaResize.
|
| 163 |
+
res_h, res_w = 1280, 720
|
| 164 |
+
transform = Compose([
|
| 165 |
+
NaResize(resolution=(res_h * res_w)**0.5, mode="area", downsample_only=False),
|
| 166 |
+
Lambda(lambda x: torch.clamp(x, 0.0, 1.0)),
|
| 167 |
+
DivisibleCrop((16, 16)),
|
| 168 |
+
Normalize(0.5, 0.5),
|
| 169 |
+
Rearrange("t c h w -> c t h w")
|
| 170 |
+
])
|
| 171 |
+
|
| 172 |
media_type, _ = mimetypes.guess_type(video_path)
|
| 173 |
is_video = media_type and media_type.startswith("video")
|
| 174 |
|
|
|
|
| 196 |
|
| 197 |
with gr.Blocks(title="SeedVR") as demo:
|
| 198 |
gr.HTML(f"""
|
| 199 |
+
|
|
|
|
|
|
|
| 200 |
<p><b>Demonstração oficial do Gradio</b> para
|
| 201 |
<a href='https://github.com/ByteDance-Seed/SeedVR' target='_blank'>
|
| 202 |
<b>SeedVR2: One-Step Video Restoration via Diffusion Adversarial Post-Training</b></a>.<br>
|
|
|
|
| 213 |
output_video = gr.Video(label="Vídeo de Saída")
|
| 214 |
download_link = gr.File(label="Baixar Resultado")
|
| 215 |
run_button.click(fn=generation_loop, inputs=[input_file, seed, fps], outputs=[output_image, output_video, download_link])
|
| 216 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
demo.queue().launch(share=True)
|