Update app.py
Browse files
app.py
CHANGED
|
@@ -72,7 +72,7 @@ def preprocess_base_images_wrapper(uploaded_files):
|
|
| 72 |
processed_paths = [aduc.process_image_for_story(f.name, 480, f"ref_processed_{i}.png") for i, f in enumerate(uploaded_files)]
|
| 73 |
return gr.update(value=processed_paths)
|
| 74 |
|
| 75 |
-
def run_mode_a_wrapper(prompt, num_keyframes, ref_files, resolution_str,
|
| 76 |
if not ref_files:
|
| 77 |
raise gr.Error("Por favor, forneça pelo menos uma imagem de referência.")
|
| 78 |
|
|
@@ -116,9 +116,10 @@ def run_mode_b_wrapper(prompt, num_keyframes, ref_files, progress=gr.Progress())
|
|
| 116 |
|
| 117 |
return gr.update(value=storyboard), gr.update(value=selected_keyframes), gr.update(visible=True, open=True)
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
handler_strength, destination_convergence_strength,
|
| 123 |
video_resolution, use_cont, use_cine,
|
| 124 |
progress=gr.Progress()):
|
|
@@ -132,10 +133,11 @@ def run_video_production_wrapper(keyframes, prompt, duration,
|
|
| 132 |
video_fragments_so_far = []
|
| 133 |
final_movie_path = None
|
| 134 |
|
| 135 |
-
# --- CHAMADA PARA O ORQUESTRADOR ATUALIZADA ---
|
| 136 |
for update in aduc.task_produce_final_movie_with_feedback(
|
| 137 |
-
keyframes, prompt,
|
| 138 |
-
int(
|
|
|
|
|
|
|
| 139 |
handler_strength, destination_convergence_strength,
|
| 140 |
resolution, use_cont, use_cine, progress
|
| 141 |
):
|
|
@@ -152,22 +154,14 @@ def run_video_production_wrapper(keyframes, prompt, duration,
|
|
| 152 |
}
|
| 153 |
|
| 154 |
def get_log_content():
|
| 155 |
-
"""Função para ler e retornar o conteúdo do arquivo de log."""
|
| 156 |
try:
|
| 157 |
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
|
| 158 |
return f.read()
|
| 159 |
except FileNotFoundError:
|
| 160 |
return "Arquivo de log ainda não criado. Inicie uma geração."
|
| 161 |
|
| 162 |
-
# --- FUNÇÃO DE TRADUÇÃO ATUALIZADA (NOVOS COMPONENTES) ---
|
| 163 |
def update_ui_language(lang_code):
|
| 164 |
lang_map = i18n.get(lang_code, i18n.get('en', {}))
|
| 165 |
-
# Adicionando traduções para os novos sliders (supondo que existam no i18n.json)
|
| 166 |
-
trim_chunks_label = lang_map.get('trim_chunks_label', 'Trim Chunks')
|
| 167 |
-
trim_chunks_info = lang_map.get('trim_chunks_info', 'How many chunks (8 frames each) to "trim" from the end before extracting the continuity guide (Echo).')
|
| 168 |
-
echo_chunks_label = lang_map.get('echo_chunks_label', 'Echo Chunks (Memory)')
|
| 169 |
-
echo_chunks_info = lang_map.get('echo_chunks_info', 'The size of the continuity guide (Echo) in chunks. This is the "memory" passed to the next scene.')
|
| 170 |
-
|
| 171 |
return {
|
| 172 |
title_md: gr.update(value=f"# {lang_map.get('app_title')}"),
|
| 173 |
subtitle_md: gr.update(value=lang_map.get('app_subtitle')),
|
|
@@ -186,9 +180,11 @@ def update_ui_language(lang_code):
|
|
| 186 |
continuity_director_checkbox: gr.update(label=lang_map.get('continuity_director_label')),
|
| 187 |
cinematographer_checkbox: gr.update(label=lang_map.get('cinematographer_label')),
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
|
| 193 |
forca_guia_slider: gr.update(label=lang_map.get('forca_guia_label'), info=lang_map.get('forca_guia_info')),
|
| 194 |
convergencia_destino_slider: gr.update(label=lang_map.get('convergencia_final_label'), info=lang_map.get('convergencia_final_info')),
|
|
@@ -215,8 +211,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 215 |
with gr.Accordion(default_lang.get('step1_accordion'), open=True) as step1_accordion:
|
| 216 |
prompt_input = gr.Textbox(label=default_lang.get('prompt_label'), value="A majestic lion walks across the savanna, sits down, and then roars at the setting sun.")
|
| 217 |
with gr.Row():
|
| 218 |
-
num_keyframes_slider = gr.Slider(minimum=3, maximum=100, value=
|
| 219 |
-
duration_per_fragment_slider = gr.Slider(label=default_lang.get('duration_label'), minimum=2.0, maximum=10.0, value=4.0, step=0.1)
|
| 220 |
ref_image_input = gr.File(label=default_lang.get('ref_images_label'), file_count="multiple", file_types=["image"])
|
| 221 |
with gr.Row():
|
| 222 |
storyboard_and_keyframes_button = gr.Button(default_lang.get('storyboard_and_keyframes_button'), variant="primary")
|
|
@@ -231,16 +227,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 231 |
continuity_director_checkbox = gr.Checkbox(label=default_lang.get('continuity_director_label'), value=True)
|
| 232 |
cinematographer_checkbox = gr.Checkbox(label=default_lang.get('cinematographer_label'), value=True, visible=False)
|
| 233 |
|
| 234 |
-
|
| 235 |
-
gr.
|
|
|
|
|
|
|
| 236 |
with gr.Row():
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
label="Chunks de Eco (Memória)",
|
| 242 |
-
info="O tamanho da guia de continuidade (Eco) em chunks. Esta é a 'memória' que passa para a próxima cena.")
|
| 243 |
-
# --- FIM DA ATUALIZAÇÃO DA UI ---
|
| 244 |
|
| 245 |
gr.Markdown("**Controle de Influência:**")
|
| 246 |
with gr.Row():
|
|
@@ -257,20 +252,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 257 |
update_log_button = gr.Button("Atualizar Log")
|
| 258 |
|
| 259 |
# --- 5. CONEXÕES DA UI ---
|
| 260 |
-
|
| 261 |
-
all_ui_components_dict = update_ui_language('pt')
|
| 262 |
-
# Adicionando os novos componentes manualmente ao dicionário para garantir que sejam incluídos
|
| 263 |
-
all_ui_components_dict[trim_chunks_slider] = None
|
| 264 |
-
all_ui_components_dict[echo_chunks_slider] = None
|
| 265 |
-
all_ui_components = list(all_ui_components_dict.keys())
|
| 266 |
-
|
| 267 |
lang_selector.change(fn=update_ui_language, inputs=lang_selector, outputs=all_ui_components)
|
| 268 |
|
| 269 |
ref_image_input.upload(fn=preprocess_base_images_wrapper, inputs=ref_image_input, outputs=ref_image_input)
|
| 270 |
|
| 271 |
storyboard_and_keyframes_button.click(
|
| 272 |
fn=run_mode_a_wrapper,
|
| 273 |
-
inputs=[prompt_input, num_keyframes_slider, ref_image_input, resolution_selector
|
| 274 |
outputs=[storyboard_output, keyframe_gallery, step3_accordion]
|
| 275 |
)
|
| 276 |
|
|
@@ -280,13 +269,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 280 |
outputs=[storyboard_output, keyframe_gallery, step3_accordion]
|
| 281 |
)
|
| 282 |
|
| 283 |
-
# --- CHAMADA DO BOTÃO ATUALIZADA ---
|
| 284 |
produce_button.click(
|
| 285 |
fn=run_video_production_wrapper,
|
| 286 |
inputs=[
|
| 287 |
-
keyframe_gallery, prompt_input,
|
| 288 |
-
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
| 290 |
forca_guia_slider,
|
| 291 |
convergencia_destino_slider,
|
| 292 |
resolution_selector, continuity_director_checkbox, cinematographer_checkbox
|
|
|
|
| 72 |
processed_paths = [aduc.process_image_for_story(f.name, 480, f"ref_processed_{i}.png") for i, f in enumerate(uploaded_files)]
|
| 73 |
return gr.update(value=processed_paths)
|
| 74 |
|
| 75 |
+
def run_mode_a_wrapper(prompt, num_keyframes, ref_files, resolution_str, progress=gr.Progress()):
|
| 76 |
if not ref_files:
|
| 77 |
raise gr.Error("Por favor, forneça pelo menos uma imagem de referência.")
|
| 78 |
|
|
|
|
| 116 |
|
| 117 |
return gr.update(value=storyboard), gr.update(value=selected_keyframes), gr.update(visible=True, open=True)
|
| 118 |
|
| 119 |
+
def run_video_production_wrapper(keyframes, prompt,
|
| 120 |
+
n_chunks_to_generate, video_end_chunk,
|
| 121 |
+
eco_start_chunk, handler_start_chunk,
|
| 122 |
+
handler_frame_target,
|
| 123 |
handler_strength, destination_convergence_strength,
|
| 124 |
video_resolution, use_cont, use_cine,
|
| 125 |
progress=gr.Progress()):
|
|
|
|
| 133 |
video_fragments_so_far = []
|
| 134 |
final_movie_path = None
|
| 135 |
|
|
|
|
| 136 |
for update in aduc.task_produce_final_movie_with_feedback(
|
| 137 |
+
keyframes, prompt,
|
| 138 |
+
int(n_chunks_to_generate), int(video_end_chunk),
|
| 139 |
+
int(eco_start_chunk), int(handler_start_chunk),
|
| 140 |
+
int(handler_frame_target),
|
| 141 |
handler_strength, destination_convergence_strength,
|
| 142 |
resolution, use_cont, use_cine, progress
|
| 143 |
):
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
def get_log_content():
|
|
|
|
| 157 |
try:
|
| 158 |
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
|
| 159 |
return f.read()
|
| 160 |
except FileNotFoundError:
|
| 161 |
return "Arquivo de log ainda não criado. Inicie uma geração."
|
| 162 |
|
|
|
|
| 163 |
def update_ui_language(lang_code):
|
| 164 |
lang_map = i18n.get(lang_code, i18n.get('en', {}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
return {
|
| 166 |
title_md: gr.update(value=f"# {lang_map.get('app_title')}"),
|
| 167 |
subtitle_md: gr.update(value=lang_map.get('app_subtitle')),
|
|
|
|
| 180 |
continuity_director_checkbox: gr.update(label=lang_map.get('continuity_director_label')),
|
| 181 |
cinematographer_checkbox: gr.update(label=lang_map.get('cinematographer_label')),
|
| 182 |
|
| 183 |
+
n_chunks_to_generate_slider: gr.update(label=lang_map.get('n_chunks_generate_label'), info=lang_map.get('n_chunks_generate_info')),
|
| 184 |
+
video_end_chunk_slider: gr.update(label=lang_map.get('video_end_chunk_label'), info=lang_map.get('video_end_chunk_info')),
|
| 185 |
+
eco_start_chunk_slider: gr.update(label=lang_map.get('eco_start_chunk_label'), info=lang_map.get('eco_start_chunk_info')),
|
| 186 |
+
handler_start_chunk_slider: gr.update(label=lang_map.get('handler_start_chunk_label'), info=lang_map.get('handler_start_chunk_info')),
|
| 187 |
+
handler_frame_target_slider: gr.update(label=lang_map.get('handler_frame_target_label'), info=lang_map.get('handler_frame_target_info')),
|
| 188 |
|
| 189 |
forca_guia_slider: gr.update(label=lang_map.get('forca_guia_label'), info=lang_map.get('forca_guia_info')),
|
| 190 |
convergencia_destino_slider: gr.update(label=lang_map.get('convergencia_final_label'), info=lang_map.get('convergencia_final_info')),
|
|
|
|
| 211 |
with gr.Accordion(default_lang.get('step1_accordion'), open=True) as step1_accordion:
|
| 212 |
prompt_input = gr.Textbox(label=default_lang.get('prompt_label'), value="A majestic lion walks across the savanna, sits down, and then roars at the setting sun.")
|
| 213 |
with gr.Row():
|
| 214 |
+
num_keyframes_slider = gr.Slider(minimum=3, maximum=100, value=5, step=1, label=default_lang.get('keyframes_label'), info="Mínimo de 3 para a lógica do cineasta.")
|
| 215 |
+
duration_per_fragment_slider = gr.Slider(label=default_lang.get('duration_label'), minimum=2.0, maximum=10.0, value=4.0, step=0.1, visible=False) # Escondido, mas mantido por dependências
|
| 216 |
ref_image_input = gr.File(label=default_lang.get('ref_images_label'), file_count="multiple", file_types=["image"])
|
| 217 |
with gr.Row():
|
| 218 |
storyboard_and_keyframes_button = gr.Button(default_lang.get('storyboard_and_keyframes_button'), variant="primary")
|
|
|
|
| 227 |
continuity_director_checkbox = gr.Checkbox(label=default_lang.get('continuity_director_label'), value=True)
|
| 228 |
cinematographer_checkbox = gr.Checkbox(label=default_lang.get('cinematographer_label'), value=True, visible=False)
|
| 229 |
|
| 230 |
+
gr.Markdown("--- \n**Controles de Geração e Continuidade (Avançado):**")
|
| 231 |
+
with gr.Row():
|
| 232 |
+
n_chunks_to_generate_slider = gr.Slider(minimum=7, maximum=25, value=13, step=1, label="Chunks a Gerar", info="Total de chunks a gerar em cada passo. Mais chunks = mais 'cauda' para as guias.")
|
| 233 |
+
video_end_chunk_slider = gr.Slider(minimum=2, maximum=20, value=9, step=1, label="Fim do Clipe (Chunk)", info="O vídeo final usará os chunks de 0 até este valor. (Ex: 9 -> usa chunks 0-8).")
|
| 234 |
with gr.Row():
|
| 235 |
+
eco_start_chunk_slider = gr.Slider(minimum=2, maximum=20, value=9, step=1, label="Início do Eco (Chunk)", info="Índice do chunk onde a guia de memória (eco) começa. (Ex: 9 -> usa chunks 9 e 10).")
|
| 236 |
+
handler_start_chunk_slider = gr.Slider(minimum=4, maximum=22, value=11, step=1, label="Início do Handler (Chunk)", info="Índice do chunk onde a guia de evolução (handler) começa. (Ex: 11 -> usa chunks 11 e 12).")
|
| 237 |
+
with gr.Row():
|
| 238 |
+
handler_frame_target_slider = gr.Slider(minimum=8, maximum=80, value=16, step=8, label="Alvo do Handler (Frame)", info="Frame exato onde a guia de evolução será aplicada na próxima geração.")
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
gr.Markdown("**Controle de Influência:**")
|
| 241 |
with gr.Row():
|
|
|
|
| 252 |
update_log_button = gr.Button("Atualizar Log")
|
| 253 |
|
| 254 |
# --- 5. CONEXÕES DA UI ---
|
| 255 |
+
all_ui_components = list(update_ui_language('pt').keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
lang_selector.change(fn=update_ui_language, inputs=lang_selector, outputs=all_ui_components)
|
| 257 |
|
| 258 |
ref_image_input.upload(fn=preprocess_base_images_wrapper, inputs=ref_image_input, outputs=ref_image_input)
|
| 259 |
|
| 260 |
storyboard_and_keyframes_button.click(
|
| 261 |
fn=run_mode_a_wrapper,
|
| 262 |
+
inputs=[prompt_input, num_keyframes_slider, ref_image_input, resolution_selector],
|
| 263 |
outputs=[storyboard_output, keyframe_gallery, step3_accordion]
|
| 264 |
)
|
| 265 |
|
|
|
|
| 269 |
outputs=[storyboard_output, keyframe_gallery, step3_accordion]
|
| 270 |
)
|
| 271 |
|
|
|
|
| 272 |
produce_button.click(
|
| 273 |
fn=run_video_production_wrapper,
|
| 274 |
inputs=[
|
| 275 |
+
keyframe_gallery, prompt_input,
|
| 276 |
+
n_chunks_to_generate_slider,
|
| 277 |
+
video_end_chunk_slider,
|
| 278 |
+
eco_start_chunk_slider,
|
| 279 |
+
handler_start_chunk_slider,
|
| 280 |
+
handler_frame_target_slider,
|
| 281 |
forca_guia_slider,
|
| 282 |
convergencia_destino_slider,
|
| 283 |
resolution_selector, continuity_director_checkbox, cinematographer_checkbox
|