Update app_seedvr.py
Browse files- app_seedvr.py +16 -9
app_seedvr.py
CHANGED
|
@@ -35,10 +35,14 @@ def _extract_first_frame(video_path: str) -> Optional[str]:
|
|
| 35 |
if not video_path or not os.path.exists(video_path): return None
|
| 36 |
try:
|
| 37 |
vid_cap = cv2.VideoCapture(video_path)
|
| 38 |
-
if not vid_cap.isOpened():
|
|
|
|
|
|
|
| 39 |
success, image = vid_cap.read()
|
| 40 |
vid_cap.release()
|
| 41 |
-
if not success:
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Salva o frame no mesmo diretório do vídeo, com extensão .jpg
|
| 44 |
image_path = Path(video_path).with_suffix(".jpg")
|
|
@@ -55,14 +59,14 @@ def on_file_upload(file_obj):
|
|
| 55 |
"""
|
| 56 |
if file_obj is None:
|
| 57 |
# Limpa os resultados e o log se o arquivo for removido
|
| 58 |
-
return 1, None, None, None, None
|
| 59 |
|
| 60 |
if _is_video(file_obj.name):
|
| 61 |
# Para vídeos, sugere um valor padrão para multi-GPU e torna o slider interativo
|
| 62 |
-
return gr.update(value=4, interactive=True), None, None, None, None
|
| 63 |
else:
|
| 64 |
# Para imagens, trava o valor em 1
|
| 65 |
-
return gr.update(value=1, interactive=False), None, None, None, None
|
| 66 |
|
| 67 |
# --- FUNÇÃO PRINCIPAL DE INFERÊNCIA DA UI ---
|
| 68 |
|
|
@@ -94,14 +98,18 @@ def run_inference_ui(
|
|
| 94 |
return
|
| 95 |
|
| 96 |
log_buffer = ["▶ Starting inference process...\n"]
|
|
|
|
| 97 |
was_input_video = _is_video(input_file_path)
|
| 98 |
|
| 99 |
try:
|
| 100 |
# Define um callback que será chamado pelo backend para atualizar o progresso e o log
|
| 101 |
def progress_callback_wrapper(step: float, desc: str):
|
| 102 |
""" Wrapper para formatar logs e atualizar o progresso. """
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
# Atualiza o objeto de progresso do Gradio
|
| 106 |
progress(step, desc=desc)
|
| 107 |
|
|
@@ -170,7 +178,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="SeedVR Media Res
|
|
| 170 |
# --- Coluna da Esquerda: Entradas e Controles ---
|
| 171 |
with gr.Column(scale=1):
|
| 172 |
gr.Markdown("### 1. Upload Media")
|
| 173 |
-
# Componente de upload agora mostra apenas o link, não a pré-visualização.
|
| 174 |
input_media = gr.File(label="Input File (Video or Image)", type="filepath", interactive=True)
|
| 175 |
|
| 176 |
gr.Markdown("### 2. Configure Settings")
|
|
@@ -190,7 +197,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="SeedVR Media Res
|
|
| 190 |
|
| 191 |
fps_out = gr.Number(label="Output FPS (for Videos)", value=24, precision=0, info="Set to 0 to use the original FPS.")
|
| 192 |
|
| 193 |
-
run_button = gr.Button("
|
| 194 |
|
| 195 |
# --- Coluna da Direita: Resultados ---
|
| 196 |
with gr.Column(scale=2):
|
|
|
|
| 35 |
if not video_path or not os.path.exists(video_path): return None
|
| 36 |
try:
|
| 37 |
vid_cap = cv2.VideoCapture(video_path)
|
| 38 |
+
if not vid_cap.isOpened():
|
| 39 |
+
print(f"Erro: Não foi possível abrir o vídeo em {video_path}")
|
| 40 |
+
return None
|
| 41 |
success, image = vid_cap.read()
|
| 42 |
vid_cap.release()
|
| 43 |
+
if not success:
|
| 44 |
+
print(f"Erro: Não foi possível ler o primeiro frame de {video_path}")
|
| 45 |
+
return None
|
| 46 |
|
| 47 |
# Salva o frame no mesmo diretório do vídeo, com extensão .jpg
|
| 48 |
image_path = Path(video_path).with_suffix(".jpg")
|
|
|
|
| 59 |
"""
|
| 60 |
if file_obj is None:
|
| 61 |
# Limpa os resultados e o log se o arquivo for removido
|
| 62 |
+
return gr.update(value=1), None, None, None, gr.update(value=None, visible=False)
|
| 63 |
|
| 64 |
if _is_video(file_obj.name):
|
| 65 |
# Para vídeos, sugere um valor padrão para multi-GPU e torna o slider interativo
|
| 66 |
+
return gr.update(value=4, interactive=True), None, None, None, gr.update(value=None, visible=False)
|
| 67 |
else:
|
| 68 |
# Para imagens, trava o valor em 1
|
| 69 |
+
return gr.update(value=1, interactive=False), None, None, None, gr.update(value=None, visible=False)
|
| 70 |
|
| 71 |
# --- FUNÇÃO PRINCIPAL DE INFERÊNCIA DA UI ---
|
| 72 |
|
|
|
|
| 98 |
return
|
| 99 |
|
| 100 |
log_buffer = ["▶ Starting inference process...\n"]
|
| 101 |
+
last_log_message = ""
|
| 102 |
was_input_video = _is_video(input_file_path)
|
| 103 |
|
| 104 |
try:
|
| 105 |
# Define um callback que será chamado pelo backend para atualizar o progresso e o log
|
| 106 |
def progress_callback_wrapper(step: float, desc: str):
|
| 107 |
""" Wrapper para formatar logs e atualizar o progresso. """
|
| 108 |
+
nonlocal last_log_message
|
| 109 |
+
# Só adiciona ao log se a mensagem for nova, para evitar poluição visual
|
| 110 |
+
if desc != last_log_message:
|
| 111 |
+
log_buffer.append(f"⏳ {desc}\n")
|
| 112 |
+
last_log_message = desc
|
| 113 |
# Atualiza o objeto de progresso do Gradio
|
| 114 |
progress(step, desc=desc)
|
| 115 |
|
|
|
|
| 178 |
# --- Coluna da Esquerda: Entradas e Controles ---
|
| 179 |
with gr.Column(scale=1):
|
| 180 |
gr.Markdown("### 1. Upload Media")
|
|
|
|
| 181 |
input_media = gr.File(label="Input File (Video or Image)", type="filepath", interactive=True)
|
| 182 |
|
| 183 |
gr.Markdown("### 2. Configure Settings")
|
|
|
|
| 197 |
|
| 198 |
fps_out = gr.Number(label="Output FPS (for Videos)", value=24, precision=0, info="Set to 0 to use the original FPS.")
|
| 199 |
|
| 200 |
+
run_button = gr.Button("Restore Media", variant="primary", icon="✨")
|
| 201 |
|
| 202 |
# --- Coluna da Direita: Resultados ---
|
| 203 |
with gr.Column(scale=2):
|