Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app_refactored_with_postprod.py (com
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
|
@@ -7,17 +7,17 @@ import traceback
|
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
# --- Import dos Serviços de Backend ---
|
| 10 |
-
|
| 11 |
-
from api.ltx_server_refactored import video_generation_service
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
from api.seedvr_server import SeedVRServer
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
seedvr_inference_server = SeedVRServer() if SeedVRServer else None
|
| 23 |
|
|
@@ -31,10 +31,9 @@ def run_generate_base_video(
|
|
| 31 |
# Parâmetros de Geração
|
| 32 |
generation_mode, prompt, neg_prompt, start_img, height, width, duration, cfg, seed, randomize_seed,
|
| 33 |
|
| 34 |
-
# Novos parâmetros LTX (
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
decode_timestep, decode_noise_scale, downscale_factor,
|
| 38 |
|
| 39 |
progress=gr.Progress(track_tqdm=True)
|
| 40 |
):
|
|
@@ -54,16 +53,11 @@ def run_generate_base_video(
|
|
| 54 |
|
| 55 |
# Agrupa todas as configurações LTX em um único dicionário para o backend
|
| 56 |
ltx_configs = {
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
"first_pass_num_inference_steps": fp_num_inference_steps,
|
| 59 |
-
"first_pass_guidance_scale": fp_guidance_scale,
|
| 60 |
-
# Gerais
|
| 61 |
-
"sampler": sampler,
|
| 62 |
-
"stg_mode": stg_mode,
|
| 63 |
-
"stochastic_sampling": stochastic_sampling,
|
| 64 |
-
"decode_timestep": decode_timestep,
|
| 65 |
-
"decode_noise_scale": decode_noise_scale,
|
| 66 |
-
"downscale_factor": downscale_factor,
|
| 67 |
}
|
| 68 |
|
| 69 |
# Decide qual função de backend chamar com base no modo
|
|
@@ -97,7 +91,6 @@ def run_ltx_refinement(state, prompt, neg_prompt, cfg, progress=gr.Progress(trac
|
|
| 97 |
if not state or not state.get("low_res_latents"):
|
| 98 |
raise gr.Error("Erro: Gere um vídeo base primeiro na Etapa 1.")
|
| 99 |
try:
|
| 100 |
-
# Nota: O refinamento também poderia aceitar um dicionário de configs para o second_pass
|
| 101 |
video_path, tensor_path = video_generation_service.generate_upscale_denoise(
|
| 102 |
latents_path=state["low_res_latents"], prompt=prompt,
|
| 103 |
negative_prompt=neg_prompt, guidance_scale=cfg, seed=state["used_seed"]
|
|
@@ -140,48 +133,34 @@ with gr.Blocks() as demo:
|
|
| 140 |
neg_prompt_input = gr.Textbox(label="Negative Prompt", value="blurry, low quality, bad anatomy", lines=2)
|
| 141 |
start_image = gr.Image(label="Imagem de Início (Opcional)", type="filepath", sources=["upload"])
|
| 142 |
|
| 143 |
-
with gr.Accordion("Parâmetros Principais", open=
|
| 144 |
duration_input = gr.Slider(label="Duração Total (s)", value=8, step=1, minimum=2, maximum=40)
|
| 145 |
with gr.Row():
|
| 146 |
-
height_input = gr.Slider(label="Height", value=
|
| 147 |
-
width_input = gr.Slider(label="Width", value=
|
| 148 |
with gr.Row():
|
| 149 |
seed_input = gr.Number(label="Seed", value=42, precision=0)
|
| 150 |
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 151 |
|
| 152 |
with gr.Accordion("Opções Adicionais LTX (Avançado)", open=False):
|
| 153 |
-
gr.
|
| 154 |
|
| 155 |
with gr.Tabs():
|
| 156 |
-
with gr.TabItem("First Pass"):
|
| 157 |
-
|
| 158 |
-
label="
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
fp_guidance_scale = gr.Slider(
|
| 162 |
-
label="Força da Guiagem (Pico)", minimum=1.0, maximum=15.0, step=0.5, value=8.0,
|
| 163 |
-
info="Padrão do config tem um pico de 8.0. Controla o quão forte o prompt guia a formação da imagem."
|
| 164 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
with gr.TabItem("Geral"):
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
info="Como o scheduler calcula os timesteps."
|
| 170 |
-
)
|
| 171 |
-
stg_mode = gr.Radio(
|
| 172 |
-
label="Modo de Guiagem Espaço-Temporal (STG)",
|
| 173 |
-
choices=["attention_values", "attention_skip", "residual", "transformer_block"],
|
| 174 |
-
value="attention_values", info="Como a guiagem de movimento é aplicada."
|
| 175 |
-
)
|
| 176 |
-
stochastic_sampling = gr.Checkbox(label="Amostragem Estocástica", value=False, info="Adiciona aleatoriedade ao denoise.")
|
| 177 |
-
downscale_factor = gr.Slider(label="Fator de Downscale", minimum=0.1, maximum=1.0, step=0.01, value=0.66, info="Tamanho da geração inicial (padrão ~0.66).")
|
| 178 |
-
|
| 179 |
-
with gr.TabItem("Decode VAE"):
|
| 180 |
-
decode_timestep = gr.Slider(label="Decode Timestep", minimum=0.0, maximum=1.0, step=0.01, value=0.05, info="Nível de ruído para o VAE denoiser.")
|
| 181 |
-
decode_noise_scale = gr.Slider(label="Decode Noise Scale", minimum=0.0, maximum=1.0, step=0.005, value=0.025, info="Escala do ruído no decode.")
|
| 182 |
-
|
| 183 |
-
cfg_input = gr.Slider(label="Guidance Scale (CFG)", info="Afeta o refinamento (se usado) e não tem efeito no First Pass dos modelos 'distilled'.", value=0.1, step=0.1, minimum=1.0, maximum=10.0)
|
| 184 |
-
|
| 185 |
generate_low_btn = gr.Button("1. Gerar Vídeo Base", variant="primary")
|
| 186 |
|
| 187 |
with gr.Column(scale=1):
|
|
@@ -209,17 +188,19 @@ with gr.Blocks() as demo:
|
|
| 209 |
seedvr_batch_size = gr.Slider(minimum=1, maximum=16, value=4, step=1, label="Batch Size por GPU")
|
| 210 |
seedvr_fps_output = gr.Number(label="FPS de Saída (0 = original)", value=0)
|
| 211 |
run_seedvr_button = gr.Button("Iniciar Upscaling SeedVR", variant="primary", interactive=(seedvr_inference_server is not None))
|
| 212 |
-
if not seedvr_inference_server:
|
| 213 |
-
gr.Markdown("<p style='color: red;'>Serviço SeedVR não disponível.</p>")
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
seedvr_video_output = gr.Video(label="Vídeo com Upscale SeedVR", interactive=False)
|
| 216 |
seedvr_status_box = gr.Textbox(label="Status", value="Aguardando...", lines=3, interactive=False)
|
| 217 |
|
| 218 |
# --- LÓGICA DE EVENTOS ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
all_ltx_inputs = [
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
decode_timestep, decode_noise_scale, downscale_factor,
|
| 223 |
]
|
| 224 |
|
| 225 |
generate_low_btn.click(
|
|
|
|
| 1 |
+
# app_refactored_with_postprod.py (com Presets de Guiagem e Opções LTX Completas)
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
# --- Import dos Serviços de Backend ---
|
| 10 |
+
try:
|
| 11 |
+
from api.ltx_server_refactored import video_generation_service
|
| 12 |
+
except ImportError:
|
| 13 |
+
print("ERRO FATAL: Não foi possível importar 'video_generation_service' de 'api.ltx_server_refactored'.")
|
| 14 |
+
sys.exit(1)
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
from api.seedvr_server import SeedVRServer
|
| 18 |
+
except ImportError:
|
| 19 |
+
print("AVISO: Não foi possível importar SeedVRServer. A aba de upscaling SeedVR será desativada.")
|
| 20 |
+
SeedVRServer = None
|
| 21 |
|
| 22 |
seedvr_inference_server = SeedVRServer() if SeedVRServer else None
|
| 23 |
|
|
|
|
| 31 |
# Parâmetros de Geração
|
| 32 |
generation_mode, prompt, neg_prompt, start_img, height, width, duration, cfg, seed, randomize_seed,
|
| 33 |
|
| 34 |
+
# Novos parâmetros LTX (com presets e customização)
|
| 35 |
+
fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list,
|
| 36 |
+
fp_num_inference_steps,
|
|
|
|
| 37 |
|
| 38 |
progress=gr.Progress(track_tqdm=True)
|
| 39 |
):
|
|
|
|
| 53 |
|
| 54 |
# Agrupa todas as configurações LTX em um único dicionário para o backend
|
| 55 |
ltx_configs = {
|
| 56 |
+
"guidance_preset": fp_guidance_preset,
|
| 57 |
+
"guidance_scale_list": fp_guidance_scale_list,
|
| 58 |
+
"stg_scale_list": fp_stg_scale_list,
|
| 59 |
+
"timesteps_list": fp_timesteps_list,
|
| 60 |
"first_pass_num_inference_steps": fp_num_inference_steps,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
|
| 63 |
# Decide qual função de backend chamar com base no modo
|
|
|
|
| 91 |
if not state or not state.get("low_res_latents"):
|
| 92 |
raise gr.Error("Erro: Gere um vídeo base primeiro na Etapa 1.")
|
| 93 |
try:
|
|
|
|
| 94 |
video_path, tensor_path = video_generation_service.generate_upscale_denoise(
|
| 95 |
latents_path=state["low_res_latents"], prompt=prompt,
|
| 96 |
negative_prompt=neg_prompt, guidance_scale=cfg, seed=state["used_seed"]
|
|
|
|
| 133 |
neg_prompt_input = gr.Textbox(label="Negative Prompt", value="blurry, low quality, bad anatomy", lines=2)
|
| 134 |
start_image = gr.Image(label="Imagem de Início (Opcional)", type="filepath", sources=["upload"])
|
| 135 |
|
| 136 |
+
with gr.Accordion("Parâmetros Principais", open=False):
|
| 137 |
duration_input = gr.Slider(label="Duração Total (s)", value=8, step=1, minimum=2, maximum=40)
|
| 138 |
with gr.Row():
|
| 139 |
+
height_input = gr.Slider(label="Height", value=720, step=32, minimum=256, maximum=1024)
|
| 140 |
+
width_input = gr.Slider(label="Width", value=480, step=32, minimum=256, maximum=1024)
|
| 141 |
with gr.Row():
|
| 142 |
seed_input = gr.Number(label="Seed", value=42, precision=0)
|
| 143 |
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 144 |
|
| 145 |
with gr.Accordion("Opções Adicionais LTX (Avançado)", open=False):
|
| 146 |
+
cfg_input = gr.Slider(label="Guidance Scale (CFG)", info="Afeta o refinamento (se usado) e não tem efeito no First Pass dos modelos 'distilled'.", value=3.0, step=0.1, minimum=1.0, maximum=10.0)
|
| 147 |
|
| 148 |
with gr.Tabs():
|
| 149 |
+
with gr.TabItem("Guiagem (First Pass)"):
|
| 150 |
+
fp_guidance_preset = gr.Dropdown(
|
| 151 |
+
label="Preset de Guiagem",
|
| 152 |
+
choices=["Padrão (Recomendado)", "Agressivo", "Suave", "Customizado"],
|
| 153 |
+
value="Padrão (Recomendado)", info="Muda o comportamento da guiagem ao longo da difusão."
|
|
|
|
|
|
|
|
|
|
| 154 |
)
|
| 155 |
+
with gr.Group(visible=False) as custom_guidance_group:
|
| 156 |
+
gr.Markdown("⚠️ Edite as listas em formato JSON. Ex: `[1, 2, 3]`")
|
| 157 |
+
fp_guidance_scale_list = gr.Textbox(label="Lista de Guidance Scale", value="[1, 1, 6, 8, 6, 1, 1]")
|
| 158 |
+
fp_stg_scale_list = gr.Textbox(label="Lista de STG Scale (Movimento)", value="[0, 0, 4, 4, 4, 2, 1]")
|
| 159 |
+
fp_timesteps_list = gr.Textbox(label="Lista de Guidance Timesteps", value="[1.0, 0.996, 0.9933, 0.9850, 0.9767, 0.9008, 0.6180]")
|
| 160 |
|
| 161 |
with gr.TabItem("Geral"):
|
| 162 |
+
fp_num_inference_steps = gr.Slider(label="Passos de Inferência (First Pass)", minimum=10, maximum=100, step=1, value=30)
|
| 163 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
generate_low_btn = gr.Button("1. Gerar Vídeo Base", variant="primary")
|
| 165 |
|
| 166 |
with gr.Column(scale=1):
|
|
|
|
| 188 |
seedvr_batch_size = gr.Slider(minimum=1, maximum=16, value=4, step=1, label="Batch Size por GPU")
|
| 189 |
seedvr_fps_output = gr.Number(label="FPS de Saída (0 = original)", value=0)
|
| 190 |
run_seedvr_button = gr.Button("Iniciar Upscaling SeedVR", variant="primary", interactive=(seedvr_inference_server is not None))
|
|
|
|
|
|
|
| 191 |
with gr.Column(scale=1):
|
| 192 |
seedvr_video_output = gr.Video(label="Vídeo com Upscale SeedVR", interactive=False)
|
| 193 |
seedvr_status_box = gr.Textbox(label="Status", value="Aguardando...", lines=3, interactive=False)
|
| 194 |
|
| 195 |
# --- LÓGICA DE EVENTOS ---
|
| 196 |
+
def update_custom_guidance_visibility(preset_choice):
|
| 197 |
+
return gr.update(visible=(preset_choice == "Customizado"))
|
| 198 |
+
|
| 199 |
+
fp_guidance_preset.change(fn=update_custom_guidance_visibility, inputs=fp_guidance_preset, outputs=custom_guidance_group)
|
| 200 |
+
|
| 201 |
all_ltx_inputs = [
|
| 202 |
+
fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list,
|
| 203 |
+
fp_num_inference_steps,
|
|
|
|
| 204 |
]
|
| 205 |
|
| 206 |
generate_low_btn.click(
|