Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,10 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Versão
|
| 6 |
#
|
| 7 |
-
# Esta versão
|
| 8 |
-
#
|
| 9 |
-
# de modelo foi removido para simplificar a experiência do usuário.
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
import yaml
|
|
@@ -17,179 +16,193 @@ import shutil
|
|
| 17 |
import time
|
| 18 |
import json
|
| 19 |
|
| 20 |
-
# --- 1. IMPORTAÇÃO DO FRAMEWORK E
|
| 21 |
import aduc_framework
|
| 22 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
cinematic_theme = gr.themes.Base(
|
| 26 |
-
|
| 27 |
-
secondary_hue=gr.themes.colors.purple,
|
| 28 |
-
neutral_hue=gr.themes.colors.slate,
|
| 29 |
-
font=(gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"),
|
| 30 |
-
).set(
|
| 31 |
-
body_background_fill="#111827", body_text_color="#E5E7EB",
|
| 32 |
-
button_primary_background_fill="linear-gradient(90deg, #4F46E5, #8B5CF6)",
|
| 33 |
-
button_primary_text_color="#FFFFFF", button_secondary_background_fill="#374151",
|
| 34 |
-
button_secondary_border_color="#4B5563", button_secondary_text_color="#E5E7EB",
|
| 35 |
-
block_background_fill="#1F2937", block_border_width="1px", block_border_color="#374151",
|
| 36 |
-
block_label_background_fill="#374151", block_label_text_color="#E5E7EB",
|
| 37 |
-
block_title_text_color="#FFFFFF", input_background_fill="#374151",
|
| 38 |
-
input_border_color="#4B5563", input_placeholder_color="#9CA3AF",
|
| 39 |
-
)
|
| 40 |
|
| 41 |
LOG_FILE_PATH = "aduc_log.txt"
|
| 42 |
-
|
| 43 |
-
os.remove(LOG_FILE_PATH)
|
| 44 |
-
|
| 45 |
-
log_format = '%(asctime)s - %(levelname)s - [%(name)s:%(funcName)s] - %(message)s'
|
| 46 |
-
root_logger = logging.getLogger()
|
| 47 |
-
root_logger.setLevel(logging.INFO)
|
| 48 |
-
root_logger.handlers.clear()
|
| 49 |
-
stream_handler = logging.StreamHandler(sys.stdout)
|
| 50 |
-
stream_handler.setFormatter(logging.Formatter(log_format))
|
| 51 |
-
root_logger.addHandler(stream_handler)
|
| 52 |
-
file_handler = logging.FileHandler(LOG_FILE_PATH, mode='w', encoding='utf-8')
|
| 53 |
-
file_handler.setFormatter(logging.Formatter(log_format))
|
| 54 |
-
root_logger.addHandler(file_handler)
|
| 55 |
-
logger = logging.getLogger(__name__)
|
| 56 |
-
|
| 57 |
-
try:
|
| 58 |
-
with open("config.yaml", 'r') as f: config = yaml.safe_load(f)
|
| 59 |
-
WORKSPACE_DIR = config['application']['workspace_dir']
|
| 60 |
-
aduc = aduc_framework.create_aduc_instance(workspace_dir=WORKSPACE_DIR)
|
| 61 |
-
logger.info("Interface Gradio inicializada e conectada ao Aduc Framework.")
|
| 62 |
-
except Exception as e:
|
| 63 |
-
logger.critical(f"ERRO CRÍTICO durante a inicialização: {e}", exc_info=True)
|
| 64 |
-
# Em caso de erro crítico, exibe a mensagem na interface do Gradio antes de sair
|
| 65 |
-
with gr.Blocks() as demo:
|
| 66 |
-
gr.Markdown("# ERRO CRÍTICO NA INICIALIZAÇÃO")
|
| 67 |
-
gr.Markdown("Não foi possível iniciar o Aduc Framework. Verifique os logs para mais detalhes.")
|
| 68 |
-
gr.Textbox(value=str(e), label="Detalhes do Erro", lines=10)
|
| 69 |
-
demo.launch()
|
| 70 |
-
exit()
|
| 71 |
-
|
| 72 |
-
# --- 2. FUNÇÕES WRAPPER (CAMADA DE TRADUÇÃO UI <-> FRAMEWORK) ---
|
| 73 |
|
|
|
|
|
|
|
|
|
|
| 74 |
def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str, duration_per_fragment, progress=gr.Progress()):
|
| 75 |
-
|
| 76 |
-
ref_paths = [aduc.process_image_for_story(f.name, 480, f"ref_processed_{i}.png") for i, f in enumerate(ref_files)]
|
| 77 |
-
params = PreProductionParams(prompt=prompt, num_keyframes=int(num_keyframes), ref_paths=ref_paths, resolution=int(resolution_str.split('x')[0]), duration_per_fragment=duration_per_fragment)
|
| 78 |
-
storyboard, final_keyframes, updated_state = aduc.task_pre_production(params, progress)
|
| 79 |
-
return updated_state.model_dump(), storyboard, final_keyframes, gr.update(visible=True, open=True)
|
| 80 |
|
|
|
|
| 81 |
def run_original_production_wrapper(current_state_dict, trim_percent, handler_strength, dest_strength, guidance_scale, stg_scale, steps, progress=gr.Progress()):
|
| 82 |
-
yield {
|
| 83 |
-
|
|
|
|
| 84 |
final_video_path, latent_paths, updated_state = aduc.task_produce_original_movie(params=production_params, progress_callback=progress)
|
| 85 |
-
|
| 86 |
-
yield {
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
final_path = None
|
| 92 |
for update in aduc.task_run_latent_upscaler(latent_paths, int(chunk_size), progress):
|
| 93 |
if "final_path" in update: final_path = update['final_path']
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def run_hd_wrapper(source_video, steps, global_prompt, progress=gr.Progress()):
|
| 97 |
-
if not source_video: raise gr.Error("
|
| 98 |
-
yield {
|
|
|
|
| 99 |
final_path = None
|
| 100 |
for update in aduc.task_run_hd_mastering(source_video, int(steps), global_prompt, progress):
|
| 101 |
if "final_path" in update: final_path = update['final_path']
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
def run_audio_wrapper(source_video, audio_prompt, global_prompt, progress=gr.Progress()):
|
| 105 |
-
if not source_video: raise gr.Error("
|
| 106 |
-
yield {
|
|
|
|
| 107 |
final_audio_prompt = audio_prompt if audio_prompt and audio_prompt.strip() else global_prompt
|
| 108 |
final_path = None
|
| 109 |
for update in aduc.task_run_audio_generation(source_video, final_audio_prompt, progress):
|
| 110 |
if "final_path" in update: final_path = update['final_path']
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
|
|
|
|
| 113 |
def get_log_content():
|
| 114 |
try:
|
| 115 |
-
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
# --- 3. DEFINIÇÃO DA UI
|
| 119 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
|
|
|
| 120 |
generation_state_holder = gr.State(value={})
|
| 121 |
original_latents_paths_state = gr.State(value=[])
|
| 122 |
-
|
| 123 |
-
current_source_video_state = gr.State(value=None)
|
| 124 |
-
upscaled_video_path_state = gr.State(value=None)
|
| 125 |
-
hd_video_path_state = gr.State(value=None)
|
| 126 |
|
| 127 |
gr.Markdown("<h1>ADUC-SDR 🎬 - O Diretor de Cinema IA</h1>")
|
| 128 |
gr.Markdown("<p>Crie um filme completo com vídeo e áudio, orquestrado por uma equipe de IAs especialistas.</p>")
|
| 129 |
|
| 130 |
-
|
| 131 |
-
lang_selector = gr.Radio(["🇧🇷", "🇺🇸", "🇨🇳"], value="🇧🇷", label="Idioma / Language")
|
| 132 |
-
resolution_selector = gr.Radio(["480x480", "720x720", "960x960"], value="480x480", label="Resolução Base")
|
| 133 |
-
|
| 134 |
with gr.Accordion("Etapa 1: Roteiro e Cenas-Chave (Pré-Produção)", open=True) as step1_accordion:
|
| 135 |
prompt_input = gr.Textbox(label="Ideia Geral do Filme", value="Um leão majestoso caminha pela savana, senta-se e ruge para o sol poente.")
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
with gr.Row():
|
| 138 |
-
num_keyframes_slider = gr.Slider(minimum=
|
| 139 |
-
duration_per_fragment_slider = gr.Slider(label="Duração de cada Clipe (s)",
|
|
|
|
| 140 |
storyboard_and_keyframes_button = gr.Button("Gerar Roteiro e Keyframes", variant="primary")
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
trim_percent_slider = gr.Slider(minimum=10, maximum=90, value=50, step=5, label="Poda Causal (%)")
|
| 146 |
-
handler_strength = gr.Slider(label="Força do Déjà-Vu", minimum=0.0, maximum=1.0, value=0.5, step=0.05)
|
| 147 |
-
dest_strength = gr.Slider(label="Força da Âncora Final", minimum=0.0, maximum=1.0, value=0.75, step=0.05)
|
| 148 |
-
guidance_scale_slider = gr.Slider(minimum=1.0, maximum=10.0, value=2.0, step=0.1, label="Escala de Orientação")
|
| 149 |
-
stg_scale_slider = gr.Slider(minimum=0.0, maximum=1.0, value=0.025, step=0.005, label="Escala STG")
|
| 150 |
-
inference_steps_slider = gr.Slider(minimum=10, maximum=50, value=20, step=1, label="Passos de Inferência")
|
| 151 |
produce_original_button = gr.Button("🎬 Produzir Vídeo Original", variant="primary")
|
| 152 |
-
original_video_output = gr.Video(label="Filme Original Master", visible=False, interactive=False)
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
with gr.Accordion("A. Upscaler Latente 2x", open=True):
|
| 157 |
upscaler_chunk_size_slider = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="Fragmentos por Lote")
|
| 158 |
run_upscaler_button = gr.Button("Executar Upscaler Latente", variant="secondary")
|
| 159 |
-
|
| 160 |
with gr.Accordion("B. Masterização HD (SeedVR)", open=True):
|
| 161 |
hd_steps_slider = gr.Slider(minimum=20, maximum=150, value=100, step=5, label="Passos de Inferência HD")
|
| 162 |
-
run_hd_button = gr.Button("Executar Masterização HD
|
| 163 |
-
|
| 164 |
with gr.Accordion("C. Geração de Áudio", open=True):
|
| 165 |
-
audio_prompt_input = gr.Textbox(label="Prompt de Áudio Detalhado (Opcional)", lines=
|
| 166 |
run_audio_button = gr.Button("Gerar Áudio", variant="secondary")
|
| 167 |
-
audio_video_output = gr.Video(label="Vídeo com Áudio", visible=False, interactive=False)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
with gr.Accordion("🧬 DNA Digital da Geração (JSON)", open=False) as data_accordion:
|
|
|
|
| 170 |
generation_data_output = gr.JSON(label="Estado de Geração Completo")
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
with gr.Accordion("📝 Log de Geração (Detalhado)", open=False) as log_accordion:
|
| 175 |
log_display = gr.Textbox(label="Log da Sessão", lines=20, interactive=False, autoscroll=True)
|
| 176 |
update_log_button = gr.Button("Atualizar Log")
|
| 177 |
|
| 178 |
-
# --- 4. CONEXÕES DE EVENTOS
|
| 179 |
-
storyboard_and_keyframes_button.click(fn=run_pre_production_wrapper, inputs=[prompt_input, num_keyframes_slider, ref_image_input, resolution_selector, duration_per_fragment_slider], outputs=[generation_state_holder, storyboard_output, keyframe_gallery, step3_accordion])
|
| 180 |
-
produce_original_button.click(fn=run_original_production_wrapper, inputs=[generation_state_holder, trim_percent_slider, handler_strength, dest_strength, guidance_scale_slider, stg_scale_slider, inference_steps_slider], outputs=[original_video_output, final_video_output, step4_accordion, original_latents_paths_state, original_video_path_state, current_source_video_state, generation_state_holder, generation_data_output])
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
update_log_button.click(fn=get_log_content, inputs=[], outputs=[log_display])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
# --- 5. INICIALIZAÇÃO DA APLICAÇÃO ---
|
| 190 |
if __name__ == "__main__":
|
| 191 |
-
|
| 192 |
-
shutil.rmtree(WORKSPACE_DIR)
|
| 193 |
-
os.makedirs(WORKSPACE_DIR)
|
| 194 |
-
logger.info("Aplicação Gradio iniciada. Lançando interface...")
|
| 195 |
-
demo.queue().launch()
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Versão 6.0.0 (Clean, Interactive & Consolidated UI)
|
| 6 |
#
|
| 7 |
+
# Esta versão refatora completamente a interface do usuário para uma experiência
|
| 8 |
+
# de coluna única, com um único player de vídeo, e adiciona um visualizador de logs.
|
|
|
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
import yaml
|
|
|
|
| 16 |
import time
|
| 17 |
import json
|
| 18 |
|
| 19 |
+
# --- 1. IMPORTAÇÃO DO FRAMEWORK E CONFIGURAÇÃO ---
|
| 20 |
import aduc_framework
|
| 21 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
| 22 |
|
| 23 |
+
# Configuração do Tema e Logging (sem alterações)
|
| 24 |
+
cinematic_theme = gr.themes.Base(...)
|
| 25 |
+
# ... (todo o código de setup de logging e do Aduc Framework) ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
LOG_FILE_PATH = "aduc_log.txt"
|
| 28 |
+
# ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# --- 2. FUNÇÕES WRAPPER ADAPTADAS PARA A NOVA UI ---
|
| 31 |
+
|
| 32 |
+
# Wrapper da pré-produção com 'yield' permanece o mesmo, pois já está otimizado
|
| 33 |
def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str, duration_per_fragment, progress=gr.Progress()):
|
| 34 |
+
# ... (código da função anterior, que já usa 'yield', continua igual) ...
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# MUDANÇA: Wrappers de produção e pós-produção agora atualizam um único player e estados
|
| 37 |
def run_original_production_wrapper(current_state_dict, trim_percent, handler_strength, dest_strength, guidance_scale, stg_scale, steps, progress=gr.Progress()):
|
| 38 |
+
yield { final_video_output: gr.update(value=None, visible=True, label="🎬 Produzindo seu filme...") }
|
| 39 |
+
|
| 40 |
+
production_params = ProductionParams(...)
|
| 41 |
final_video_path, latent_paths, updated_state = aduc.task_produce_original_movie(params=production_params, progress_callback=progress)
|
| 42 |
+
|
| 43 |
+
yield {
|
| 44 |
+
final_video_output: gr.update(value=final_video_path, label="✅ Filme Original Master"),
|
| 45 |
+
step4_accordion: gr.update(visible=True, open=True),
|
| 46 |
+
original_latents_paths_state: latent_paths,
|
| 47 |
+
current_source_video_state: final_video_path, # Estado principal para a próxima etapa
|
| 48 |
+
generation_state_holder: updated_state.model_dump(),
|
| 49 |
+
generation_data_output: updated_state.model_dump()
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
def run_upscaler_wrapper(source_video, latent_paths, chunk_size, progress=gr.Progress()):
|
| 53 |
+
if not source_video or not latent_paths: raise gr.Error("Fonte de vídeo ou latentes originais não encontrados para o Upscaler.")
|
| 54 |
+
yield { final_video_output: gr.update(label="Pós-Produção: Upscaler Latente...") }
|
| 55 |
+
|
| 56 |
final_path = None
|
| 57 |
for update in aduc.task_run_latent_upscaler(latent_paths, int(chunk_size), progress):
|
| 58 |
if "final_path" in update: final_path = update['final_path']
|
| 59 |
+
|
| 60 |
+
yield {
|
| 61 |
+
final_video_output: gr.update(value=final_path, label="✅ Upscale Latente Concluído"),
|
| 62 |
+
current_source_video_state: final_path # Atualiza o estado para a próxima etapa
|
| 63 |
+
}
|
| 64 |
|
| 65 |
def run_hd_wrapper(source_video, steps, global_prompt, progress=gr.Progress()):
|
| 66 |
+
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Masterização HD.")
|
| 67 |
+
yield { final_video_output: gr.update(label="Pós-Produção: Masterização HD...") }
|
| 68 |
+
|
| 69 |
final_path = None
|
| 70 |
for update in aduc.task_run_hd_mastering(source_video, int(steps), global_prompt, progress):
|
| 71 |
if "final_path" in update: final_path = update['final_path']
|
| 72 |
+
|
| 73 |
+
yield {
|
| 74 |
+
final_video_output: gr.update(value=final_path, label="✅ Masterização HD Concluída"),
|
| 75 |
+
current_source_video_state: final_path # Atualiza o estado para a próxima etapa
|
| 76 |
+
}
|
| 77 |
|
| 78 |
def run_audio_wrapper(source_video, audio_prompt, global_prompt, progress=gr.Progress()):
|
| 79 |
+
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Geração de Áudio.")
|
| 80 |
+
yield { final_video_output: gr.update(label="Pós-Produção: Geração de Áudio...") }
|
| 81 |
+
|
| 82 |
final_audio_prompt = audio_prompt if audio_prompt and audio_prompt.strip() else global_prompt
|
| 83 |
final_path = None
|
| 84 |
for update in aduc.task_run_audio_generation(source_video, final_audio_prompt, progress):
|
| 85 |
if "final_path" in update: final_path = update['final_path']
|
| 86 |
+
|
| 87 |
+
yield {
|
| 88 |
+
final_video_output: gr.update(value=final_path, label="✅ Filme Final com Áudio")
|
| 89 |
+
}
|
| 90 |
|
| 91 |
+
# NOVA FUNÇÃO: Para ler o arquivo de log
|
| 92 |
def get_log_content():
|
| 93 |
try:
|
| 94 |
+
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
|
| 95 |
+
return f.read()
|
| 96 |
+
except FileNotFoundError:
|
| 97 |
+
return "Arquivo de log ainda não criado."
|
| 98 |
|
| 99 |
+
# --- 3. DEFINIÇÃO DA NOVA UI ---
|
| 100 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
| 101 |
+
# MUDANÇA: Estados para gerenciar os caminhos dos vídeos nos bastidores
|
| 102 |
generation_state_holder = gr.State(value={})
|
| 103 |
original_latents_paths_state = gr.State(value=[])
|
| 104 |
+
current_source_video_state = gr.State(value=None) # O estado mais importante
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
gr.Markdown("<h1>ADUC-SDR 🎬 - O Diretor de Cinema IA</h1>")
|
| 107 |
gr.Markdown("<p>Crie um filme completo com vídeo e áudio, orquestrado por uma equipe de IAs especialistas.</p>")
|
| 108 |
|
| 109 |
+
# --- ETAPA 1: PRÉ-PRODUÇÃO (ENTRADAS PRINCIPAIS) ---
|
|
|
|
|
|
|
|
|
|
| 110 |
with gr.Accordion("Etapa 1: Roteiro e Cenas-Chave (Pré-Produção)", open=True) as step1_accordion:
|
| 111 |
prompt_input = gr.Textbox(label="Ideia Geral do Filme", value="Um leão majestoso caminha pela savana, senta-se e ruge para o sol poente.")
|
| 112 |
+
|
| 113 |
+
with gr.Row():
|
| 114 |
+
lang_selector = gr.Radio(["🇧🇷", "🇺🇸", "🇨🇳"], value="🇧🇷", label="Idioma / Language")
|
| 115 |
+
resolution_selector = gr.Radio(["512x512", "768x768", "1024x1024"], value="512x512", label="Resolução Base")
|
| 116 |
+
|
| 117 |
+
# MUDANÇA: Grupo de Imagens do Usuário
|
| 118 |
+
ref_image_input = gr.File(label="Imagens de Referência (Grupo de Imagens do Usuário)", file_count="multiple", file_types=["image"])
|
| 119 |
+
|
| 120 |
with gr.Row():
|
| 121 |
+
num_keyframes_slider = gr.Slider(minimum=2, maximum=42, value=4, step=2, label="Número de Cenas-Chave (Par)")
|
| 122 |
+
duration_per_fragment_slider = gr.Slider(label="Duração de cada Clipe (s)", minimum=2.0, maximum=10.0, value=4.0, step=0.1)
|
| 123 |
+
|
| 124 |
storyboard_and_keyframes_button = gr.Button("Gerar Roteiro e Keyframes", variant="primary")
|
| 125 |
+
|
| 126 |
+
# --- ETAPA 2: PRODUÇÃO ---
|
| 127 |
+
with gr.Accordion("Etapa 2: Produção do Vídeo Original", open=False, visible=False) as step3_accordion:
|
| 128 |
+
# ... (Sliders de Poda Causal, Força do Déjà-Vu, etc. continuam aqui)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
produce_original_button = gr.Button("🎬 Produzir Vídeo Original", variant="primary")
|
|
|
|
| 130 |
|
| 131 |
+
# --- ETAPA 3: PÓS-PRODUÇÃO ---
|
| 132 |
+
with gr.Accordion("Etapa 3: Pós-Produção (Opcional)", open=False, visible=False) as step4_accordion:
|
| 133 |
+
gr.Markdown("Aplique melhorias ao filme. Cada etapa usa o resultado da anterior como fonte.")
|
| 134 |
+
|
| 135 |
with gr.Accordion("A. Upscaler Latente 2x", open=True):
|
| 136 |
upscaler_chunk_size_slider = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="Fragmentos por Lote")
|
| 137 |
run_upscaler_button = gr.Button("Executar Upscaler Latente", variant="secondary")
|
| 138 |
+
|
| 139 |
with gr.Accordion("B. Masterização HD (SeedVR)", open=True):
|
| 140 |
hd_steps_slider = gr.Slider(minimum=20, maximum=150, value=100, step=5, label="Passos de Inferência HD")
|
| 141 |
+
run_hd_button = gr.Button("Executar Masterização HD", variant="secondary")
|
| 142 |
+
|
| 143 |
with gr.Accordion("C. Geração de Áudio", open=True):
|
| 144 |
+
audio_prompt_input = gr.Textbox(label="Prompt de Áudio Detalhado (Opcional)", lines=2, placeholder="Descreva os sons, efeitos e música. Se vazio, usará o prompt geral.")
|
| 145 |
run_audio_button = gr.Button("Gerar Áudio", variant="secondary")
|
|
|
|
| 146 |
|
| 147 |
+
# --- MUDANÇA: GRUPOS DE VISUALIZAÇÃO DE RESULTADOS ---
|
| 148 |
+
|
| 149 |
+
# Vídeo Final (ÚNICO PLAYER)
|
| 150 |
+
final_video_output = gr.Video(label="Filme Final (Resultado da Última Etapa)", visible=False, interactive=False)
|
| 151 |
+
|
| 152 |
+
# Grupo das Keyframes
|
| 153 |
+
with gr.Accordion("Galeria de Cenas-Chave (Keyframes)", open=False) as keyframes_accordion:
|
| 154 |
+
keyframe_gallery = gr.Gallery(label="Keyframes Gerados", visible=True, object_fit="contain", height="auto")
|
| 155 |
+
|
| 156 |
+
# DNA Digital (JSON)
|
| 157 |
with gr.Accordion("🧬 DNA Digital da Geração (JSON)", open=False) as data_accordion:
|
| 158 |
+
storyboard_output = gr.JSON(label="Roteiro Gerado (Storyboard)")
|
| 159 |
generation_data_output = gr.JSON(label="Estado de Geração Completo")
|
| 160 |
|
| 161 |
+
# NOVO: Log de Geração
|
|
|
|
| 162 |
with gr.Accordion("📝 Log de Geração (Detalhado)", open=False) as log_accordion:
|
| 163 |
log_display = gr.Textbox(label="Log da Sessão", lines=20, interactive=False, autoscroll=True)
|
| 164 |
update_log_button = gr.Button("Atualizar Log")
|
| 165 |
|
| 166 |
+
# --- 4. CONEXÕES DE EVENTOS REFEITAS ---
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
# Pré-Produção (com streaming)
|
| 169 |
+
storyboard_and_keyframes_button.click(
|
| 170 |
+
fn=run_pre_production_wrapper,
|
| 171 |
+
inputs=[prompt_input, num_keyframes_slider, ref_image_input, resolution_selector, duration_per_fragment_slider],
|
| 172 |
+
outputs=[generation_state_holder, storyboard_output, keyframe_gallery, step3_accordion]
|
| 173 |
+
)
|
| 174 |
|
| 175 |
+
# Produção
|
| 176 |
+
produce_original_button.click(
|
| 177 |
+
fn=run_original_production_wrapper,
|
| 178 |
+
inputs=[generation_state_holder, ...], # todos os sliders da produção
|
| 179 |
+
outputs=[final_video_output, step4_accordion, original_latents_paths_state, current_source_video_state, generation_state_holder, generation_data_output]
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Pós-Produção (em cadeia, usando o 'current_source_video_state')
|
| 183 |
+
run_upscaler_button.click(
|
| 184 |
+
fn=run_upscaler_wrapper,
|
| 185 |
+
inputs=[current_source_video_state, original_latents_paths_state, upscaler_chunk_size_slider],
|
| 186 |
+
outputs=[final_video_output, current_source_video_state]
|
| 187 |
+
)
|
| 188 |
+
run_hd_button.click(
|
| 189 |
+
fn=run_hd_wrapper,
|
| 190 |
+
inputs=[current_source_video_state, hd_steps_slider, prompt_input],
|
| 191 |
+
outputs=[final_video_output, current_source_video_state]
|
| 192 |
+
)
|
| 193 |
+
run_audio_button.click(
|
| 194 |
+
fn=run_audio_wrapper,
|
| 195 |
+
inputs=[current_source_video_state, audio_prompt_input, prompt_input],
|
| 196 |
+
outputs=[final_video_output] # Última etapa, não precisa atualizar o source_state
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
# Conexão do botão de Log
|
| 200 |
update_log_button.click(fn=get_log_content, inputs=[], outputs=[log_display])
|
| 201 |
+
|
| 202 |
+
# Atualiza o JSON de estado sempre que ele muda
|
| 203 |
+
generation_state_holder.change(fn=lambda state: state, inputs=generation_state_holder, outputs=generation_data_output)
|
| 204 |
+
|
| 205 |
|
| 206 |
# --- 5. INICIALIZAÇÃO DA APLICAÇÃO ---
|
| 207 |
if __name__ == "__main__":
|
| 208 |
+
# ... (código de limpeza do workspace e demo.launch())
|
|
|
|
|
|
|
|
|
|
|
|