Update app.py
Browse files
app.py
CHANGED
|
@@ -1,213 +1,249 @@
|
|
| 1 |
-
# app.py (Versão
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
import os
|
| 6 |
import imageio
|
| 7 |
-
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
TARGET_FIXED_SIDE = 768
|
| 23 |
MIN_DIM_SLIDER = 256
|
| 24 |
MAX_IMAGE_SIZE = 1280
|
| 25 |
|
| 26 |
def calculate_new_dimensions(orig_w, orig_h):
|
|
|
|
| 27 |
if orig_w == 0 or orig_h == 0: return int(TARGET_FIXED_SIDE), int(TARGET_FIXED_SIDE)
|
| 28 |
if orig_w >= orig_h:
|
| 29 |
new_h, aspect_ratio = TARGET_FIXED_SIDE, orig_w / orig_h
|
| 30 |
new_w = round((new_h * aspect_ratio) / 32) * 32
|
| 31 |
-
new_w = max(MIN_DIM_SLIDER, min(new_w, MAX_IMAGE_SIZE))
|
| 32 |
-
new_h = max(MIN_DIM_SLIDER, min(new_h, MAX_IMAGE_SIZE))
|
| 33 |
else:
|
| 34 |
new_w, aspect_ratio = TARGET_FIXED_SIDE, orig_h / orig_w
|
| 35 |
new_h = round((new_w * aspect_ratio) / 32) * 32
|
| 36 |
-
|
| 37 |
-
new_w = max(MIN_DIM_SLIDER, min(new_w, MAX_IMAGE_SIZE))
|
| 38 |
-
return int(new_h), int(new_w)
|
| 39 |
|
| 40 |
def handle_media_upload_for_dims(filepath, current_h, current_w):
|
|
|
|
| 41 |
if not filepath or not os.path.exists(str(filepath)): return gr.update(value=current_h), gr.update(value=current_w)
|
| 42 |
try:
|
| 43 |
if str(filepath).lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
|
| 44 |
-
with Image.open(filepath) as img:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
with imageio.get_reader(filepath) as reader:
|
| 48 |
-
meta = reader.get_meta_data()
|
| 49 |
-
orig_w, orig_h = meta.get('size', (current_w, current_h))
|
| 50 |
new_h, new_w = calculate_new_dimensions(orig_w, orig_h)
|
| 51 |
return gr.update(value=new_h), gr.update(value=new_w)
|
| 52 |
except Exception as e:
|
| 53 |
-
print(f"Erro ao processar mídia
|
| 54 |
return gr.update(value=current_h), gr.update(value=current_w)
|
| 55 |
|
| 56 |
def update_frame_slider(duration):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
max_frames = int(duration * fps)
|
| 60 |
-
# Garante que o valor padrão não seja maior que o novo máximo
|
| 61 |
new_value = 48 if max_frames >= 48 else max_frames // 2
|
| 62 |
return gr.update(maximum=max_frames, value=new_value)
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
def
|
| 67 |
-
prompt, negative_prompt, mode,
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
middle_image, middle_frame, middle_weight,
|
| 71 |
-
end_image, end_weight,
|
| 72 |
-
# Outras entradas
|
| 73 |
-
input_video, height, width, duration,
|
| 74 |
-
frames_to_use, seed, randomize_seed,
|
| 75 |
-
guidance_scale, improve_texture,
|
| 76 |
progress=gr.Progress(track_tqdm=True)
|
| 77 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
try:
|
| 79 |
def progress_handler(step, total_steps):
|
| 80 |
-
progress(step / total_steps, desc="
|
| 81 |
|
| 82 |
-
output_path, used_seed =
|
| 83 |
prompt=prompt, negative_prompt=negative_prompt, mode=mode,
|
| 84 |
-
start_image_filepath=start_image,
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
end_image_weight=end_weight,
|
| 90 |
-
input_video_filepath=input_video,
|
| 91 |
-
height=int(height), width=int(width), duration=float(duration),
|
| 92 |
-
frames_to_use=int(frames_to_use), seed=int(seed),
|
| 93 |
randomize_seed=bool(randomize_seed), guidance_scale=float(guidance_scale),
|
| 94 |
improve_texture=bool(improve_texture), progress_callback=progress_handler
|
| 95 |
)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
with gr.Blocks(css=css) as demo:
|
| 106 |
-
gr.Markdown("# LTX Video com Keyframes")
|
| 107 |
-
gr.Markdown("Guie a geração de vídeo usando imagens de início, meio e fim.")
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
with gr.Row():
|
| 110 |
with gr.Column():
|
|
|
|
| 111 |
with gr.Tab("image-to-video (Keyframes)") as image_tab:
|
|
|
|
| 112 |
i2v_prompt = gr.Textbox(label="Prompt", value="Uma bela transição entre as imagens", lines=2)
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
with gr.Column(scale=1):
|
| 116 |
-
gr.Markdown("#### Início (Obrigatório)")
|
| 117 |
-
start_image_i2v = gr.Image(label="Imagem de Início", type="filepath", sources=["upload", "clipboard"])
|
| 118 |
-
with gr.Column(scale=1):
|
| 119 |
-
gr.Markdown("#### Meio (Opcional)")
|
| 120 |
-
middle_image_i2v = gr.Image(label="Imagem do Meio", type="filepath", sources=["upload", "clipboard"])
|
| 121 |
-
middle_frame_i2v = gr.Slider(label="Frame Alvo", minimum=0, maximum=200, step=1, value=48)
|
| 122 |
-
middle_weight_i2v = gr.Slider(label="Peso/Força", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
|
| 123 |
-
with gr.Column(scale=1):
|
| 124 |
-
gr.Markdown("#### Fim (Opcional)")
|
| 125 |
-
end_image_i2v = gr.Image(label="Imagem de Fim", type="filepath", sources=["upload", "clipboard"])
|
| 126 |
-
end_weight_i2v = gr.Slider(label="Peso/Força", minimum=0.0, maximum=1.0, step=0.05, value=1.0)
|
| 127 |
-
|
| 128 |
i2v_button = gr.Button("Generate Image-to-Video", variant="primary")
|
| 129 |
|
| 130 |
with gr.Tab("text-to-video") as text_tab:
|
| 131 |
t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3)
|
| 132 |
t2v_button = gr.Button("Generate Text-to-Video", variant="primary")
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
v2v_prompt = gr.Textbox(label="Prompt", value="Change the style to cinematic anime", lines=3)
|
| 138 |
-
v2v_button = gr.Button("Generate Video-to-Video", variant="primary")
|
| 139 |
-
|
| 140 |
-
duration_input = gr.Slider(label="Video Duration (seconds)", minimum=0.3, maximum=8.5, value=4, step=0.1)
|
| 141 |
-
improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True, visible=True)
|
| 142 |
-
|
| 143 |
with gr.Column():
|
| 144 |
-
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
with gr.Accordion("Advanced settings", open=False):
|
|
|
|
| 147 |
mode = gr.Dropdown(["text-to-video", "image-to-video", "video-to-video"], label="task", value="image-to-video", visible=False)
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
# Reescrevendo as listas de inputs de forma explícita para evitar erros.
|
| 169 |
-
|
| 170 |
-
# Placeholders para os botões que não usam certos inputs
|
| 171 |
-
none_image = gr.Textbox(visible=False, value=None)
|
| 172 |
-
none_video = gr.Textbox(visible=False, value=None)
|
| 173 |
-
|
| 174 |
-
# Parâmetros comuns a todos
|
| 175 |
-
shared_params = [
|
| 176 |
-
height_input, width_input, duration_input, frames_to_use,
|
| 177 |
-
seed_input, randomize_seed_input, guidance_scale_input, improve_texture
|
| 178 |
-
]
|
| 179 |
-
|
| 180 |
-
i2v_inputs = [
|
| 181 |
-
i2v_prompt, negative_prompt_input, mode,
|
| 182 |
-
start_image_i2v, middle_image_i2v, middle_frame_i2v, middle_weight_i2v,
|
| 183 |
-
end_image_i2v, end_weight_i2v,
|
| 184 |
-
none_video, # Placeholder para input_video
|
| 185 |
-
*shared_params
|
| 186 |
-
]
|
| 187 |
-
|
| 188 |
-
t2v_inputs = [
|
| 189 |
-
t2v_prompt, negative_prompt_input, mode,
|
| 190 |
-
none_image, none_image, gr.Number(value=-1, visible=False), gr.Slider(value=0, visible=False), # Placeholders para keyframes
|
| 191 |
-
none_image, gr.Slider(value=0, visible=False),
|
| 192 |
-
none_video, # Placeholder para input_video
|
| 193 |
-
*shared_params
|
| 194 |
-
]
|
| 195 |
-
|
| 196 |
-
v2v_inputs = [
|
| 197 |
-
v2v_prompt, negative_prompt_input, mode,
|
| 198 |
-
none_image, none_image, gr.Number(value=-1, visible=False), gr.Slider(value=0, visible=False), # Placeholders para keyframes
|
| 199 |
-
none_image, gr.Slider(value=0, visible=False),
|
| 200 |
-
video_v2v, # Input de vídeo real
|
| 201 |
-
*shared_params
|
| 202 |
-
]
|
| 203 |
-
|
| 204 |
-
common_outputs = [output_video, seed_input]
|
| 205 |
-
|
| 206 |
-
i2v_button.click(fn=gradio_generate_wrapper, inputs=i2v_inputs, outputs=common_outputs, api_name="image_to_video_keyframes")
|
| 207 |
-
t2v_button.click(fn=gradio_generate_wrapper, inputs=t2v_inputs, outputs=common_outputs, api_name="text_to_video")
|
| 208 |
-
v2v_button.click(fn=gradio_generate_wrapper, inputs=v2v_inputs, outputs=common_outputs, api_name="video_to_video")
|
| 209 |
-
# --- <FIM DA CORREÇÃO> ---
|
| 210 |
-
|
| 211 |
|
| 212 |
if __name__ == "__main__":
|
|
|
|
| 213 |
demo.queue().launch(debug=True, share=False)
|
|
|
|
| 1 |
+
# app.py (Versão Unificada LTX + SeedVR)
|
| 2 |
|
| 3 |
+
# --- 0. WARNINGS E SETUP ---
|
| 4 |
+
import warnings
|
| 5 |
+
warnings.filterwarnings("ignore")
|
| 6 |
import gradio as gr
|
| 7 |
from PIL import Image
|
| 8 |
import os
|
| 9 |
import imageio
|
| 10 |
+
import multiprocessing as mp
|
| 11 |
|
| 12 |
+
# --- 1. IMPORTAÇÃO DOS DOIS SERVIÇOS ---
|
| 13 |
|
| 14 |
+
# Importa o serviço de geração do LTX
|
| 15 |
+
try:
|
| 16 |
+
from api.ltx_server import video_generation_service
|
| 17 |
+
except ImportError:
|
| 18 |
+
raise ImportError("Falha ao importar o 'video_generation_service' de 'api.ltx_server'.")
|
| 19 |
|
| 20 |
+
# Importa o serviço de upscale do SeedVR
|
| 21 |
+
try:
|
| 22 |
+
from api.seedvr_server import SeedVRServer
|
| 23 |
+
except ImportError:
|
| 24 |
+
raise ImportError("Falha ao importar o 'SeedVRServer' de 'api.seedvr_server'.")
|
| 25 |
|
| 26 |
+
# --- 2. INICIALIZAÇÃO DOS SERVIÇOS ---
|
| 27 |
+
print("🚀 Inicializando o serviço de geração LTX-Video...")
|
| 28 |
+
ltx_service = video_generation_service
|
| 29 |
+
print("✅ Serviço LTX-Video pronto.")
|
| 30 |
|
| 31 |
+
print("🚀 Inicializando o serviço de upscale SeedVR...")
|
| 32 |
+
seedvr_service = SeedVRServer()
|
| 33 |
+
print("✅ Serviço SeedVR pronto.")
|
| 34 |
|
| 35 |
+
|
| 36 |
+
# --- 3. FUNÇÕES HELPER DA UI (sem grandes alterações) ---
|
| 37 |
TARGET_FIXED_SIDE = 768
|
| 38 |
MIN_DIM_SLIDER = 256
|
| 39 |
MAX_IMAGE_SIZE = 1280
|
| 40 |
|
| 41 |
def calculate_new_dimensions(orig_w, orig_h):
|
| 42 |
+
# ... (código inalterado)
|
| 43 |
if orig_w == 0 or orig_h == 0: return int(TARGET_FIXED_SIDE), int(TARGET_FIXED_SIDE)
|
| 44 |
if orig_w >= orig_h:
|
| 45 |
new_h, aspect_ratio = TARGET_FIXED_SIDE, orig_w / orig_h
|
| 46 |
new_w = round((new_h * aspect_ratio) / 32) * 32
|
|
|
|
|
|
|
| 47 |
else:
|
| 48 |
new_w, aspect_ratio = TARGET_FIXED_SIDE, orig_h / orig_w
|
| 49 |
new_h = round((new_w * aspect_ratio) / 32) * 32
|
| 50 |
+
return int(max(MIN_DIM_SLIDER, min(new_h, MAX_IMAGE_SIZE))), int(max(MIN_DIM_SLIDER, min(new_w, MAX_IMAGE_SIZE)))
|
|
|
|
|
|
|
| 51 |
|
| 52 |
def handle_media_upload_for_dims(filepath, current_h, current_w):
|
| 53 |
+
# ... (código inalterado)
|
| 54 |
if not filepath or not os.path.exists(str(filepath)): return gr.update(value=current_h), gr.update(value=current_w)
|
| 55 |
try:
|
| 56 |
if str(filepath).lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
|
| 57 |
+
with Image.open(filepath) as img: orig_w, orig_h = img.size
|
| 58 |
+
else:
|
| 59 |
+
with imageio.get_reader(filepath) as reader: meta = reader.get_meta_data(); orig_w, orig_h = meta.get('size', (current_w, current_h))
|
|
|
|
|
|
|
|
|
|
| 60 |
new_h, new_w = calculate_new_dimensions(orig_w, orig_h)
|
| 61 |
return gr.update(value=new_h), gr.update(value=new_w)
|
| 62 |
except Exception as e:
|
| 63 |
+
print(f"Erro ao processar mídia: {e}")
|
| 64 |
return gr.update(value=current_h), gr.update(value=current_w)
|
| 65 |
|
| 66 |
def update_frame_slider(duration):
|
| 67 |
+
# ... (código inalterado)
|
| 68 |
+
max_frames = int(duration * 24.0)
|
|
|
|
|
|
|
| 69 |
new_value = 48 if max_frames >= 48 else max_frames // 2
|
| 70 |
return gr.update(maximum=max_frames, value=new_value)
|
| 71 |
|
| 72 |
+
# --- 4. FUNÇÕES DE CALLBACK PARA CADA ETAPA ---
|
| 73 |
|
| 74 |
+
# ETAPA 1: Geração com LTX
|
| 75 |
+
def run_ltx_generation(
|
| 76 |
+
prompt, negative_prompt, mode, start_image, middle_image, middle_frame,
|
| 77 |
+
middle_weight, end_image, end_weight, input_video, height, width,
|
| 78 |
+
duration, frames_to_use, seed, randomize_seed, guidance_scale, improve_texture,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
progress=gr.Progress(track_tqdm=True)
|
| 80 |
):
|
| 81 |
+
# Limpa os resultados da etapa anterior (SeedVR) e mostra o container de upscale
|
| 82 |
+
yield (
|
| 83 |
+
gr.update(interactive=False, value="Generating with LTX..."), # Botão LTX
|
| 84 |
+
None, # Vídeo LTX
|
| 85 |
+
gr.update(visible=False), # Container de upscale
|
| 86 |
+
gr.update(value=None, visible=False), # Log SeedVR
|
| 87 |
+
gr.update(value=None, visible=False) # Vídeo SeedVR
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
try:
|
| 91 |
def progress_handler(step, total_steps):
|
| 92 |
+
progress(step / total_steps, desc="Saving LTX video...")
|
| 93 |
|
| 94 |
+
output_path, used_seed = ltx_service.generate(
|
| 95 |
prompt=prompt, negative_prompt=negative_prompt, mode=mode,
|
| 96 |
+
start_image_filepath=start_image, middle_image_filepath=middle_image,
|
| 97 |
+
middle_frame_number=middle_frame, middle_image_weight=middle_weight,
|
| 98 |
+
end_image_filepath=end_image, end_image_weight=end_weight,
|
| 99 |
+
input_video_filepath=input_video, height=int(height), width=int(width),
|
| 100 |
+
duration=float(duration), frames_to_use=int(frames_to_use), seed=int(seed),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
randomize_seed=bool(randomize_seed), guidance_scale=float(guidance_scale),
|
| 102 |
improve_texture=bool(improve_texture), progress_callback=progress_handler
|
| 103 |
)
|
| 104 |
+
|
| 105 |
+
# Mostra o resultado do LTX e o container de upscale
|
| 106 |
+
yield (
|
| 107 |
+
gr.update(interactive=True, value="Generate Video"),
|
| 108 |
+
gr.update(value=output_path),
|
| 109 |
+
gr.update(visible=True), # Mostra o container de upscale
|
| 110 |
+
gr.update(visible=False),
|
| 111 |
+
gr.update(value=None, visible=False)
|
| 112 |
+
)
|
| 113 |
except Exception as e:
|
| 114 |
+
gr.Error(f"LTX Generation Failed: {e}")
|
| 115 |
+
yield gr.update(interactive=True, value="Generate Video"), None, gr.update(visible=False), None, None
|
| 116 |
+
|
| 117 |
+
# ETAPA 2: Upscale com SeedVR
|
| 118 |
+
def run_seedvr_upscale(
|
| 119 |
+
ltx_video_path: str, # Recebe o caminho do vídeo gerado
|
| 120 |
+
resolution: str,
|
| 121 |
+
sp_size: int,
|
| 122 |
+
progress=gr.Progress(track_tqdm=True)
|
| 123 |
+
):
|
| 124 |
+
# Desabilita o botão de upscale e mostra os componentes de log/vídeo
|
| 125 |
+
yield (
|
| 126 |
+
gr.update(interactive=False, value="Upscaling with SeedVR..."),
|
| 127 |
+
gr.update(value="▶ Starting SeedVR upscale process...\n", visible=True),
|
| 128 |
+
gr.update(value=None, visible=False)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
if not ltx_video_path:
|
| 132 |
+
gr.Warning("No video from LTX to process.")
|
| 133 |
+
yield gr.update(interactive=True), gr.update(value="No input video.", visible=True), None
|
| 134 |
+
return
|
| 135 |
|
| 136 |
+
log_buffer = ["▶ Starting SeedVR upscale process...\n"]
|
| 137 |
+
last_log_message = ""
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
try:
|
| 140 |
+
def progress_callback_wrapper(step: float, desc: str):
|
| 141 |
+
nonlocal last_log_message
|
| 142 |
+
if desc != last_log_message:
|
| 143 |
+
log_buffer.append(f"{desc}\n")
|
| 144 |
+
last_log_message = desc
|
| 145 |
+
progress(step, desc=desc)
|
| 146 |
+
|
| 147 |
+
final_video_path = seedvr_service.run_inference_direct(
|
| 148 |
+
file_path=ltx_video_path,
|
| 149 |
+
seed=42,
|
| 150 |
+
res_h=int(resolution),
|
| 151 |
+
res_w=int(resolution),
|
| 152 |
+
sp_size=int(sp_size),
|
| 153 |
+
fps=None, # Usa o FPS original
|
| 154 |
+
progress=progress_callback_wrapper
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
log_buffer.append("✅ SeedVR Upscale complete!")
|
| 158 |
+
|
| 159 |
+
yield (
|
| 160 |
+
gr.update(interactive=True, value="Refine and Upscale with SeedVR"),
|
| 161 |
+
''.join(log_buffer),
|
| 162 |
+
gr.update(value=final_video_path, visible=True)
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
except Exception as e:
|
| 166 |
+
error_message = f"❌ SeedVR Upscale Failed: {e}"
|
| 167 |
+
gr.Error(error_message)
|
| 168 |
+
log_buffer.append(f"\n{error_message}")
|
| 169 |
+
yield gr.update(interactive=True), ''.join(log_buffer), None
|
| 170 |
+
|
| 171 |
+
# --- 5. DEFINIÇÃO DA INTERFACE GRADIO UNIFICADA ---
|
| 172 |
+
css = "#col-container { margin: 0 auto; max-width: 900px; }"
|
| 173 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
| 174 |
+
gr.Markdown("# LTX-Video + SeedVR: Pipeline de Geração e Refinamento")
|
| 175 |
+
|
| 176 |
+
# --- ETAPA 1: GERAÇÃO (LTX) ---
|
| 177 |
+
gr.Markdown("## Etapa 1: Gerar Vídeo Base com LTX-Video")
|
| 178 |
with gr.Row():
|
| 179 |
with gr.Column():
|
| 180 |
+
# ... (Toda a UI do LTX-Video que você já tem vai aqui)
|
| 181 |
with gr.Tab("image-to-video (Keyframes)") as image_tab:
|
| 182 |
+
# ...
|
| 183 |
i2v_prompt = gr.Textbox(label="Prompt", value="Uma bela transição entre as imagens", lines=2)
|
| 184 |
+
start_image_i2v = gr.Image(label="Imagem de Início", type="filepath")
|
| 185 |
+
# ... etc ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
i2v_button = gr.Button("Generate Image-to-Video", variant="primary")
|
| 187 |
|
| 188 |
with gr.Tab("text-to-video") as text_tab:
|
| 189 |
t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3)
|
| 190 |
t2v_button = gr.Button("Generate Text-to-Video", variant="primary")
|
| 191 |
+
|
| 192 |
+
# ... (outras abas e configurações do LTX)
|
| 193 |
|
| 194 |
+
duration_input = gr.Slider(label="Video Duration (seconds)", minimum=1, maximum=30, value=8, step=0.5)
|
| 195 |
+
improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True)
|
| 196 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
with gr.Column():
|
| 198 |
+
ltx_output_video = gr.Video(label="LTX Generated Video", interactive=False)
|
| 199 |
|
| 200 |
+
# --- ETAPA 2: UPSCALE (SeedVR) ---
|
| 201 |
+
with gr.Box(visible=False) as upscale_container:
|
| 202 |
+
gr.Markdown("---")
|
| 203 |
+
gr.Markdown("## Etapa 2: Refinar e Aumentar Resolução com SeedVR (Multi-GPU)")
|
| 204 |
+
|
| 205 |
+
with gr.Row():
|
| 206 |
+
with gr.Column(scale=1):
|
| 207 |
+
seedvr_resolution = gr.Dropdown(
|
| 208 |
+
label="Target Resolution",
|
| 209 |
+
choices=["720", "960", "1024", "2048"],
|
| 210 |
+
value="1024"
|
| 211 |
+
)
|
| 212 |
+
seedvr_sp_size = gr.Slider(
|
| 213 |
+
label="Frames per Batch (sp_size)",
|
| 214 |
+
minimum=1, maximum=16, step=1, value=4
|
| 215 |
+
)
|
| 216 |
+
upscale_button = gr.Button("Refine and Upscale with SeedVR", variant="primary", icon="💎")
|
| 217 |
+
|
| 218 |
+
with gr.Column(scale=2):
|
| 219 |
+
seedvr_log_window = gr.Textbox(label="SeedVR Inference Log 📝", lines=8, visible=False, autoscroll=True)
|
| 220 |
+
seedvr_output_video = gr.Video(label="Final Upscaled Video", visible=False)
|
| 221 |
+
|
| 222 |
+
# --- Acorddion de Configs Avançadas (como antes) ---
|
| 223 |
with gr.Accordion("Advanced settings", open=False):
|
| 224 |
+
# ... (todos os inputs avançados do LTX)
|
| 225 |
mode = gr.Dropdown(["text-to-video", "image-to-video", "video-to-video"], label="task", value="image-to-video", visible=False)
|
| 226 |
+
# ...
|
| 227 |
+
|
| 228 |
+
# --- LÓGICA DE EVENTOS ---
|
| 229 |
+
# ... (eventos de upload e seleção de abas do LTX, como antes) ...
|
| 230 |
+
|
| 231 |
+
# Evento do botão de geração do LTX
|
| 232 |
+
ltx_inputs = [...] # Sua lista completa de inputs para o LTX
|
| 233 |
+
i2v_button.click(
|
| 234 |
+
fn=run_ltx_generation,
|
| 235 |
+
inputs=ltx_inputs,
|
| 236 |
+
outputs=[i2v_button, ltx_output_video, upscale_container, seedvr_log_window, seedvr_output_video]
|
| 237 |
+
)
|
| 238 |
+
# (faça o mesmo para t2v_button e v2v_button)
|
| 239 |
+
|
| 240 |
+
# Evento do botão de upscale do SeedVR
|
| 241 |
+
upscale_button.click(
|
| 242 |
+
fn=run_seedvr_upscale,
|
| 243 |
+
inputs=[ltx_output_video, seedvr_resolution, seedvr_sp_size],
|
| 244 |
+
outputs=[upscale_button, seedvr_log_window, seedvr_output_video]
|
| 245 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
if __name__ == "__main__":
|
| 248 |
+
mp.set_start_method('spawn', force=True)
|
| 249 |
demo.queue().launch(debug=True, share=False)
|