Carlex22222 commited on
Commit
8ee2f06
·
verified ·
1 Parent(s): 3d5bbef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py (VERSÃO FINAL E CORRIGIDA)
2
 
3
  import gradio as gr
4
  import os
@@ -7,19 +7,25 @@ import shutil
7
  import subprocess
8
  import mimetypes
9
  from pathlib import Path
10
- from torch.hub import download_url_to_file
11
 
12
  # --- BLOCO DE CONFIGURAÇÃO E DOWNLOAD DE MODELO ---
13
  APP_DIR = "/app"; SEEDVR_DIR = os.path.join(APP_DIR, "SeedVR")
14
  MODEL_CACHE_DIR = "/tmp/models"; CKPTS_DIR = os.path.join(MODEL_CACHE_DIR, "ckpts")
15
  os.makedirs(CKPTS_DIR, exist_ok=True)
 
 
 
 
 
 
16
  files_to_download = {
17
  "seedvr2_ema_3b.pth": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth",
18
  "ema_vae.pth": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/ema_vae.pth",
19
  "pos_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt",
20
  "neg_emb.pt": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt",
21
  }
22
- print("Verificando e baixando modelos para /tmp/models/ckpts...")
23
  for filename, url in files_to_download.items():
24
  destination_path = os.path.join(CKPTS_DIR, filename)
25
  if not os.path.exists(destination_path):
@@ -28,6 +34,7 @@ for filename, url in files_to_download.items():
28
  print("Verificação de modelos concluída.")
29
  # --------------------------------------------------------------------
30
 
 
31
  def run_inference(video_path, seed, res_h, res_w):
32
  if video_path is None: raise gr.Error("Por favor, faça o upload de um arquivo.")
33
  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)
@@ -65,7 +72,6 @@ def run_inference(video_path, seed, res_h, res_w):
65
  shutil.rmtree(input_dir, ignore_errors=True)
66
  if os.path.exists(patched_script_path): os.remove(patched_script_path)
67
 
68
- # --- Interface Gráfica Gradio ---
69
  with gr.Blocks(css="footer {display: none !important}") as demo:
70
  gr.Markdown("# 🚀 Interface de Inferência para SeedVR2")
71
  gr.Markdown("Faça o upload de um vídeo ou imagem, ajuste os parâmetros e clique em 'Executar'.")
@@ -83,9 +89,7 @@ with gr.Blocks(css="footer {display: none !important}") as demo:
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
-
87
- # !!! A CORREÇÃO FINAL ESTÁ AQUI !!!
88
- # Estas duas chamadas foram movidas para DENTRO do bloco 'with gr.Blocks()'.
89
  run_button.click(
90
  fn=run_inference,
91
  inputs=[input_media, seed, res_h, res_w],
 
1
+ # app.py (VERSÃO FINAL COM LAZY IMPORT)
2
 
3
  import gradio as gr
4
  import os
 
7
  import subprocess
8
  import mimetypes
9
  from pathlib import Path
10
+ # A importação do torch.hub foi REMOVIDA daqui
11
 
12
  # --- BLOCO DE CONFIGURAÇÃO E DOWNLOAD DE MODELO ---
13
  APP_DIR = "/app"; SEEDVR_DIR = os.path.join(APP_DIR, "SeedVR")
14
  MODEL_CACHE_DIR = "/tmp/models"; CKPTS_DIR = os.path.join(MODEL_CACHE_DIR, "ckpts")
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
+
22
  files_to_download = {
23
  "seedvr2_ema_3b.pth": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth",
24
  "ema_vae.pth": "https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/ema_vae.pth",
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):
 
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)
 
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'.")
 
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
  run_button.click(
94
  fn=run_inference,
95
  inputs=[input_media, seed, res_h, res_w],