Eueuiaa commited on
Commit
8bbdce0
·
verified ·
1 Parent(s): 2134e1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -41
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py
2
 
3
  import gradio as gr
4
  import os
@@ -10,13 +10,13 @@ from pathlib import Path
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'.")
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.")
20
  SeedVRServer = None
21
 
22
  seedvr_inference_server = SeedVRServer() if SeedVRServer else None
@@ -26,14 +26,18 @@ def create_initial_state():
26
  return {"low_res_video": None, "low_res_latents": None, "used_seed": None}
27
 
28
  # --- FUNÇÕES WRAPPER PARA A UI ---
 
29
  def run_generate_base_video(
30
- generation_mode, prompt, neg_prompt, start_img, height, width, duration,
31
- seed, randomize_seed,
32
- fp_num_inference_steps, ship_initial_inference_steps, ship_final_inference_steps,
33
  fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list,
34
  progress=gr.Progress(track_tqdm=True)
35
  ):
 
 
 
36
  print(f"UI: Iniciando geração no modo: {generation_mode}")
 
37
  try:
38
  initial_image_conditions = []
39
  if start_img:
@@ -43,33 +47,34 @@ def run_generate_base_video(
43
 
44
  used_seed = None if randomize_seed else seed
45
 
 
46
  ltx_configs = {
47
  "guidance_preset": fp_guidance_preset,
48
  "guidance_scale_list": fp_guidance_scale_list,
49
  "stg_scale_list": fp_stg_scale_list,
50
  "timesteps_list": fp_timesteps_list,
51
- "fp_num_inference_steps": fp_num_inference_steps,
52
- "ship_initial_inference_steps": ship_initial_inference_steps,
53
- "ship_final_inference_steps": ship_final_inference_steps,
54
  }
55
 
 
56
  if generation_mode == "Narrativa (Múltiplos Prompts)":
57
- video_path, tensor_path, final_seed = video_generation_service.generate_low(
58
- prompt=prompt, negative_prompt=neg_prompt, height=height, width=width, duration=duration,
59
- seed=used_seed, conditions_itens=initial_image_conditions,
 
 
60
  ltx_configs_override=ltx_configs,
61
  )
62
- else:
63
- video_path, tensor_path, final_seed = video_generation_service.generate_low(
64
- prompt=prompt, negative_prompt=neg_prompt, height=height, width=width, duration=duration,
65
- seed=used_seed, conditions_itens=initial_image_conditions,
 
 
66
  ltx_configs_override=ltx_configs,
67
  )
68
 
69
- if video_path is None:
70
- raise gr.Error("A geração do vídeo falhou no backend. Verifique os logs do console para detalhes.")
71
-
72
  new_state = {"low_res_video": video_path, "low_res_latents": tensor_path, "used_seed": final_seed}
 
73
  return video_path, new_state, gr.update(visible=True)
74
 
75
  except Exception as e:
@@ -77,13 +82,13 @@ def run_generate_base_video(
77
  print(f"{error_message}\nDetalhes: {traceback.format_exc()}")
78
  raise gr.Error(error_message)
79
 
80
- def run_ltx_refinement(state, prompt, neg_prompt, progress=gr.Progress(track_tqdm=True)):
81
  if not state or not state.get("low_res_latents"):
82
  raise gr.Error("Erro: Gere um vídeo base primeiro na Etapa 1.")
83
  try:
84
  video_path, tensor_path = video_generation_service.generate_upscale_denoise(
85
  latents_path=state["low_res_latents"], prompt=prompt,
86
- negative_prompt=neg_prompt, seed=state["used_seed"]
87
  )
88
  state["refined_video_ltx"] = video_path; state["refined_latents_ltx"] = tensor_path
89
  return video_path, state
@@ -108,6 +113,7 @@ def run_seedvr_upscaling(state, seed, resolution, batch_size, fps, progress=gr.P
108
  # --- DEFINIÇÃO DA INTERFACE GRADIO ---
109
  with gr.Blocks() as demo:
110
  gr.Markdown("# LTX Video - Geração e Pós-Produção por Etapas")
 
111
  app_state = gr.State(value=create_initial_state())
112
 
113
  with gr.Row():
@@ -122,16 +128,21 @@ with gr.Blocks() as demo:
122
  neg_prompt_input = gr.Textbox(label="Negative Prompt", value="blurry, low quality, bad anatomy", lines=2)
123
  start_image = gr.Image(label="Imagem de Início (Opcional)", type="filepath", sources=["upload"])
124
 
125
- with gr.Accordion("Parâmetros Principais", open=True):
126
- duration_input = gr.Slider(label="Duração Total (s)", value=8, step=1, minimum=1, maximum=40)
127
  with gr.Row():
128
- height_input = gr.Slider(label="Height", value=512, step=32, minimum=256, maximum=1024)
129
- width_input = gr.Slider(label="Width", value=704, step=32, minimum=256, maximum=1024)
130
  with gr.Row():
131
  seed_input = gr.Number(label="Seed", value=42, precision=0)
132
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
133
 
134
  with gr.Accordion("Opções Adicionais LTX (Avançado)", open=False):
 
 
 
 
 
135
  with gr.Tabs():
136
  with gr.TabItem("Guiagem (First Pass)"):
137
  fp_guidance_preset = gr.Dropdown(
@@ -144,12 +155,7 @@ with gr.Blocks() as demo:
144
  fp_guidance_scale_list = gr.Textbox(label="Lista de Guidance Scale", value="[1, 1, 6, 8, 6, 1, 1]")
145
  fp_stg_scale_list = gr.Textbox(label="Lista de STG Scale (Movimento)", value="[0, 0, 4, 4, 4, 2, 1]")
146
  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]")
147
-
148
- with gr.TabItem("Scheduler"):
149
- fp_num_inference_steps = gr.Slider(label="Passos de Inferência", minimum=10, maximum=100, step=1, value=30)
150
- ship_initial_inference_steps = gr.Slider(label="Pular Passos Iniciais (img2vid)", minimum=0, maximum=100, step=1, value=0)
151
- ship_final_inference_steps = gr.Slider(label="Pular Passos Finais", minimum=0, maximum=100, step=1, value=0)
152
-
153
  generate_low_btn = gr.Button("1. Gerar Vídeo Base", variant="primary")
154
 
155
  with gr.Column(scale=1):
@@ -179,33 +185,30 @@ with gr.Blocks() as demo:
179
  with gr.Column(scale=1):
180
  seedvr_video_output = gr.Video(label="Vídeo com Upscale SeedVR", interactive=False)
181
  seedvr_status_box = gr.Textbox(label="Status", value="Aguardando...", lines=3, interactive=False)
182
-
183
-
184
  def update_custom_guidance_visibility(preset_choice):
185
  return gr.update(visible=(preset_choice == "Customizado"))
186
 
187
  fp_guidance_preset.change(fn=update_custom_guidance_visibility, inputs=fp_guidance_preset, outputs=custom_guidance_group)
188
 
189
  all_ltx_inputs = [
190
- fp_num_inference_steps, ship_initial_inference_steps, ship_final_inference_steps,
191
- fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list,
192
  ]
193
 
194
  generate_low_btn.click(
195
  fn=run_generate_base_video,
196
  inputs=[
197
- generation_mode_input, prompt_input, neg_prompt_input, start_image,
198
- height_input, width_input, duration_input,
199
- seed_input, randomize_seed,
200
- *all_ltx_inputs,
201
- # Passa o `cfg` por último, pois não está no `all_ltx_inputs`
202
  ],
203
  outputs=[low_res_video_output, app_state, post_prod_group]
204
  )
205
 
206
  ltx_refine_btn.click(
207
  fn=run_ltx_refinement,
208
- inputs=[app_state, prompt_input, neg_prompt_input],
209
  outputs=[ltx_refined_video_output, app_state]
210
  )
211
 
 
1
+ # app_refactored_with_postprod.py (com Presets de Guiagem e Opções LTX Completas)
2
 
3
  import gradio as gr
4
  import os
 
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
 
26
  return {"low_res_video": None, "low_res_latents": None, "used_seed": None}
27
 
28
  # --- FUNÇÕES WRAPPER PARA A UI ---
29
+
30
  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
  fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list,
34
  progress=gr.Progress(track_tqdm=True)
35
  ):
36
+ """
37
+ Função wrapper que decide qual pipeline de backend chamar, passando todas as configurações LTX.
38
+ """
39
  print(f"UI: Iniciando geração no modo: {generation_mode}")
40
+
41
  try:
42
  initial_image_conditions = []
43
  if start_img:
 
47
 
48
  used_seed = None if randomize_seed else seed
49
 
50
+ # Agrupa todas as configurações LTX em um único dicionário para o backend
51
  ltx_configs = {
52
  "guidance_preset": fp_guidance_preset,
53
  "guidance_scale_list": fp_guidance_scale_list,
54
  "stg_scale_list": fp_stg_scale_list,
55
  "timesteps_list": fp_timesteps_list,
 
 
 
56
  }
57
 
58
+ # Decide qual função de backend chamar com base no modo
59
  if generation_mode == "Narrativa (Múltiplos Prompts)":
60
+ video_path, tensor_path, final_seed = video_generation_service.generate_narrative_low(
61
+ prompt=prompt, negative_prompt=neg_prompt,
62
+ height=height, width=width, duration=duration,
63
+ guidance_scale=cfg, seed=used_seed,
64
+ initial_image_conditions=initial_image_conditions,
65
  ltx_configs_override=ltx_configs,
66
  )
67
+ else: # Modo "Simples (Prompt Único)"
68
+ video_path, tensor_path, final_seed = video_generation_service.generate_single_low(
69
+ prompt=prompt, negative_prompt=neg_prompt,
70
+ height=height, width=width, duration=duration,
71
+ guidance_scale=cfg, seed=used_seed,
72
+ initial_image_conditions=initial_image_conditions,
73
  ltx_configs_override=ltx_configs,
74
  )
75
 
 
 
 
76
  new_state = {"low_res_video": video_path, "low_res_latents": tensor_path, "used_seed": final_seed}
77
+
78
  return video_path, new_state, gr.update(visible=True)
79
 
80
  except Exception as e:
 
82
  print(f"{error_message}\nDetalhes: {traceback.format_exc()}")
83
  raise gr.Error(error_message)
84
 
85
+ def run_ltx_refinement(state, prompt, neg_prompt, cfg, progress=gr.Progress(track_tqdm=True)):
86
  if not state or not state.get("low_res_latents"):
87
  raise gr.Error("Erro: Gere um vídeo base primeiro na Etapa 1.")
88
  try:
89
  video_path, tensor_path = video_generation_service.generate_upscale_denoise(
90
  latents_path=state["low_res_latents"], prompt=prompt,
91
+ negative_prompt=neg_prompt, guidance_scale=cfg, seed=state["used_seed"]
92
  )
93
  state["refined_video_ltx"] = video_path; state["refined_latents_ltx"] = tensor_path
94
  return video_path, state
 
113
  # --- DEFINIÇÃO DA INTERFACE GRADIO ---
114
  with gr.Blocks() as demo:
115
  gr.Markdown("# LTX Video - Geração e Pós-Produção por Etapas")
116
+
117
  app_state = gr.State(value=create_initial_state())
118
 
119
  with gr.Row():
 
128
  neg_prompt_input = gr.Textbox(label="Negative Prompt", value="blurry, low quality, bad anatomy", lines=2)
129
  start_image = gr.Image(label="Imagem de Início (Opcional)", type="filepath", sources=["upload"])
130
 
131
+ with gr.Accordion("Parâmetros Principais", open=False):
132
+ duration_input = gr.Slider(label="Duração Total (s)", value=1, step=1, minimum=1, maximum=40)
133
  with gr.Row():
134
+ height_input = gr.Slider(label="Height", value=720, step=32, minimum=256, maximum=1024)
135
+ width_input = gr.Slider(label="Width", value=720, step=32, minimum=256, maximum=1024)
136
  with gr.Row():
137
  seed_input = gr.Number(label="Seed", value=42, precision=0)
138
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
139
 
140
  with gr.Accordion("Opções Adicionais LTX (Avançado)", open=False):
141
+ 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.0, step=1, minimum=0.0, maximum=10.0)
142
+ fp_num_inference_steps = gr.Slider(label="Passos de Inferência (First Pass)", minimum=10, maximum=100, step=1, value=10)
143
+ ship_initial_inference_steps = gr.Slider(label="Passos de Inferência (Ship First)", minimum=0, maximum=100, step=1, value=0)
144
+ ship_final_inference_steps = gr.Slider(label="Passos de Inferência (Ship Last)", minimum=0, maximum=100, step=1, value=0)
145
+
146
  with gr.Tabs():
147
  with gr.TabItem("Guiagem (First Pass)"):
148
  fp_guidance_preset = gr.Dropdown(
 
155
  fp_guidance_scale_list = gr.Textbox(label="Lista de Guidance Scale", value="[1, 1, 6, 8, 6, 1, 1]")
156
  fp_stg_scale_list = gr.Textbox(label="Lista de STG Scale (Movimento)", value="[0, 0, 4, 4, 4, 2, 1]")
157
  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]")
158
+
 
 
 
 
 
159
  generate_low_btn = gr.Button("1. Gerar Vídeo Base", variant="primary")
160
 
161
  with gr.Column(scale=1):
 
185
  with gr.Column(scale=1):
186
  seedvr_video_output = gr.Video(label="Vídeo com Upscale SeedVR", interactive=False)
187
  seedvr_status_box = gr.Textbox(label="Status", value="Aguardando...", lines=3, interactive=False)
188
+
189
+ # --- LÓGICA DE EVENTOS ---
190
  def update_custom_guidance_visibility(preset_choice):
191
  return gr.update(visible=(preset_choice == "Customizado"))
192
 
193
  fp_guidance_preset.change(fn=update_custom_guidance_visibility, inputs=fp_guidance_preset, outputs=custom_guidance_group)
194
 
195
  all_ltx_inputs = [
196
+ fp_guidance_preset, fp_guidance_scale_list, fp_stg_scale_list, fp_timesteps_list
 
197
  ]
198
 
199
  generate_low_btn.click(
200
  fn=run_generate_base_video,
201
  inputs=[
202
+ generation_mode_input, prompt_input, neg_prompt_input, start_image, height_input, width_input,
203
+ duration_input, 4, seed_input, randomize_seed,
204
+ *all_ltx_inputs
 
 
205
  ],
206
  outputs=[low_res_video_output, app_state, post_prod_group]
207
  )
208
 
209
  ltx_refine_btn.click(
210
  fn=run_ltx_refinement,
211
+ inputs=[app_state, prompt_input, neg_prompt_input, cfg_input],
212
  outputs=[ltx_refined_video_output, app_state]
213
  )
214