Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,6 @@ MODEL_CACHE_DIR = "/tmp/models"; CKPTS_DIR = os.path.join(MODEL_CACHE_DIR, "ckpt
|
|
| 15 |
os.makedirs(CKPTS_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
print("Verificando e baixando modelos para /tmp/models/ckpts...")
|
| 18 |
-
# !!! A MUDANÇA CRUCIAL ESTÁ AQUI !!!
|
| 19 |
# A importação é feita apenas quando necessária.
|
| 20 |
from torch.hub import download_url_to_file
|
| 21 |
|
|
@@ -25,16 +24,14 @@ files_to_download = {
|
|
| 25 |
"pos_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt",
|
| 26 |
"neg_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt",
|
| 27 |
}
|
| 28 |
-
|
| 29 |
for filename, url in files_to_download.items():
|
| 30 |
destination_path = os.path.join(CKPTS_DIR, filename)
|
| 31 |
if not os.path.exists(destination_path):
|
| 32 |
print(f"Baixando {filename}..."); download_url_to_file(url, destination_path)
|
| 33 |
else: print(f"{filename} já existe.")
|
| 34 |
print("Verificação de modelos concluída.")
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
# O resto do código (run_inference, UI do Gradio) permanece o mesmo.
|
| 38 |
def run_inference(video_path, seed, res_h, res_w):
|
| 39 |
if video_path is None: raise gr.Error("Por favor, faça o upload de um arquivo.")
|
| 40 |
job_id = str(uuid.uuid4()); input_dir = os.path.join("/tmp", "temp_inputs", job_id); output_dir = os.path.join("/tmp", "temp_outputs", job_id)
|
|
@@ -71,11 +68,9 @@ def run_inference(video_path, seed, res_h, res_w):
|
|
| 71 |
finally:
|
| 72 |
shutil.rmtree(input_dir, ignore_errors=True)
|
| 73 |
if os.path.exists(patched_script_path): os.remove(patched_script_path)
|
| 74 |
-
|
| 75 |
with gr.Blocks(css="footer {display: none !important}") as demo:
|
| 76 |
gr.Markdown("# 🚀 Interface de Inferência para SeedVR2")
|
| 77 |
gr.Markdown("Faça o upload de um vídeo ou imagem, ajuste os parâmetros e clique em 'Executar'.")
|
| 78 |
-
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column(scale=1):
|
| 81 |
input_media = gr.Video(label="Upload de Vídeo ou Imagem")
|
|
@@ -84,25 +79,10 @@ with gr.Blocks(css="footer {display: none !important}") as demo:
|
|
| 84 |
res_h = gr.Number(value=720, label="Altura da Saída (res_h)")
|
| 85 |
res_w = gr.Number(value=1280, label="Largura da Saída (res_w)")
|
| 86 |
run_button = gr.Button("Executar", variant="primary")
|
| 87 |
-
|
| 88 |
with gr.Column(scale=2):
|
| 89 |
output_image = gr.Image(label="Saída de Imagem")
|
| 90 |
output_video = gr.Video(label="Saída de Vídeo")
|
| 91 |
log_box = gr.Textbox(label="Logs em Tempo Real", lines=15, autoscroll=True, interactive=False)
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
inputs=[input_media, seed, res_h, res_w],
|
| 96 |
-
outputs=[output_image, output_video, log_box]
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
gr.Examples(
|
| 100 |
-
examples=[
|
| 101 |
-
["./SeedVR/01.mp4", 666],
|
| 102 |
-
["./SeedVR/02.mp4", 123],
|
| 103 |
-
["./SeedVR/03.mp4", 42],
|
| 104 |
-
],
|
| 105 |
-
inputs=[input_media, seed]
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
demo.queue(max_size=10).launch()
|
|
|
|
| 15 |
os.makedirs(CKPTS_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
print("Verificando e baixando modelos para /tmp/models/ckpts...")
|
|
|
|
| 18 |
# A importação é feita apenas quando necessária.
|
| 19 |
from torch.hub import download_url_to_file
|
| 20 |
|
|
|
|
| 24 |
"pos_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt",
|
| 25 |
"neg_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt",
|
| 26 |
}
|
|
|
|
| 27 |
for filename, url in files_to_download.items():
|
| 28 |
destination_path = os.path.join(CKPTS_DIR, filename)
|
| 29 |
if not os.path.exists(destination_path):
|
| 30 |
print(f"Baixando {filename}..."); download_url_to_file(url, destination_path)
|
| 31 |
else: print(f"{filename} já existe.")
|
| 32 |
print("Verificação de modelos concluída.")
|
| 33 |
+
# --- O resto do código permanece o mesmo ---
|
| 34 |
+
# (Cole o resto do seu app.py funcional aqui)
|
|
|
|
| 35 |
def run_inference(video_path, seed, res_h, res_w):
|
| 36 |
if video_path is None: raise gr.Error("Por favor, faça o upload de um arquivo.")
|
| 37 |
job_id = str(uuid.uuid4()); input_dir = os.path.join("/tmp", "temp_inputs", job_id); output_dir = os.path.join("/tmp", "temp_outputs", job_id)
|
|
|
|
| 68 |
finally:
|
| 69 |
shutil.rmtree(input_dir, ignore_errors=True)
|
| 70 |
if os.path.exists(patched_script_path): os.remove(patched_script_path)
|
|
|
|
| 71 |
with gr.Blocks(css="footer {display: none !important}") as demo:
|
| 72 |
gr.Markdown("# 🚀 Interface de Inferência para SeedVR2")
|
| 73 |
gr.Markdown("Faça o upload de um vídeo ou imagem, ajuste os parâmetros e clique em 'Executar'.")
|
|
|
|
| 74 |
with gr.Row():
|
| 75 |
with gr.Column(scale=1):
|
| 76 |
input_media = gr.Video(label="Upload de Vídeo ou Imagem")
|
|
|
|
| 79 |
res_h = gr.Number(value=720, label="Altura da Saída (res_h)")
|
| 80 |
res_w = gr.Number(value=1280, label="Largura da Saída (res_w)")
|
| 81 |
run_button = gr.Button("Executar", variant="primary")
|
|
|
|
| 82 |
with gr.Column(scale=2):
|
| 83 |
output_image = gr.Image(label="Saída de Imagem")
|
| 84 |
output_video = gr.Video(label="Saída de Vídeo")
|
| 85 |
log_box = gr.Textbox(label="Logs em Tempo Real", lines=15, autoscroll=True, interactive=False)
|
| 86 |
+
run_button.click(fn=run_inference, inputs=[input_media, seed, res_h, res_w], outputs=[output_image, output_video, log_box])
|
| 87 |
+
gr.Examples(examples=[["./SeedVR/01.mp4", 666],["./SeedVR/02.mp4", 123],["./SeedVR/03.mp4", 42]], inputs=[input_media, seed])
|
| 88 |
+
demo.queue(max_size=10).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|