Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,9 @@
|
|
| 4 |
#
|
| 5 |
# Versão 6.1.0 (UI with Integrated VQA Testing)
|
| 6 |
#
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
-
# de
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
import yaml
|
|
@@ -20,14 +20,57 @@ import json
|
|
| 20 |
# --- 1. IMPORTAÇÕES DO FRAMEWORK ---
|
| 21 |
import aduc_framework
|
| 22 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
| 23 |
-
# IMPORTAÇÃO DO NOVO ESPECIALISTA
|
| 24 |
from aduc_framework.managers.vision_qa_manager import vision_qa_manager_singleton
|
| 25 |
|
| 26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# --- 2. FUNÇÕES WRAPPER (UI <-> FRAMEWORK) ---
|
| 29 |
|
| 30 |
-
# AJUSTE: Wrapper de pré-produção agora salva os caminhos das imagens de referência
|
| 31 |
def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str, duration_per_fragment, progress=gr.Progress()):
|
| 32 |
if not ref_files: raise gr.Error("Por favor, forneça pelo menos uma imagem de referência.")
|
| 33 |
|
|
@@ -36,7 +79,6 @@ def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str,
|
|
| 36 |
|
| 37 |
params = PreProductionParams(prompt=prompt, num_keyframes=int(num_keyframes), ref_paths=ref_paths, resolution=target_resolution, duration_per_fragment=duration_per_fragment)
|
| 38 |
|
| 39 |
-
# Emite o estado inicial que inclui os caminhos das imagens para o teste de VQA
|
| 40 |
yield { reference_images_state: ref_paths }
|
| 41 |
|
| 42 |
final_result = {}
|
|
@@ -53,35 +95,68 @@ def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str,
|
|
| 53 |
step3_accordion: gr.update(visible=True, open=True)
|
| 54 |
}
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
answer = vision_qa_manager_singleton.answer_on_video(video_path=source_video, question=question)
|
| 69 |
yield answer
|
| 70 |
|
| 71 |
def answer_images_wrapper(image_paths, question):
|
| 72 |
-
|
| 73 |
-
if not
|
| 74 |
-
raise gr.Error("Nenhuma imagem de referência foi carregada para ser analisada.")
|
| 75 |
-
if not question or not question.strip():
|
| 76 |
-
raise gr.Error("Por favor, digite uma pergunta.")
|
| 77 |
-
|
| 78 |
yield "Analisando as imagens de referência..."
|
| 79 |
-
|
| 80 |
-
all_answers = []
|
| 81 |
-
for i, path in enumerate(image_paths):
|
| 82 |
-
answer = vision_qa_manager_singleton.answer_on_image(image_path=path, question=question)
|
| 83 |
-
all_answers.append(f"--- Imagem de Referência {i+1} ({os.path.basename(path)}) ---\nResposta: {answer}\n")
|
| 84 |
-
|
| 85 |
yield "\n".join(all_answers)
|
| 86 |
|
| 87 |
def get_log_content():
|
|
@@ -91,68 +166,86 @@ def get_log_content():
|
|
| 91 |
|
| 92 |
# --- 3. DEFINIÇÃO DA UI ---
|
| 93 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
| 94 |
-
# Estados
|
| 95 |
generation_state_holder = gr.State(value={})
|
| 96 |
original_latents_paths_state = gr.State(value=[])
|
| 97 |
current_source_video_state = gr.State(value=None)
|
| 98 |
-
reference_images_state = gr.State(value=[])
|
| 99 |
|
| 100 |
gr.Markdown("<h1>ADUC-SDR 🎬 - O Diretor de Cinema IA</h1>")
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
# --- NOVA SEÇÃO DE TESTES VQA ---
|
| 112 |
with gr.Accordion("🧪 Etapa de Análise Visual (VQA - Teste)", open=False) as vqa_accordion:
|
| 113 |
with gr.Blocks():
|
| 114 |
gr.Markdown("### Analisar o Vídeo Final")
|
| 115 |
video_q_input = gr.Textbox(label="Faça uma pergunta sobre o vídeo gerado", placeholder="Ex: O leão chega a beber água?")
|
| 116 |
video_q_button = gr.Button("Perguntar ao Vídeo")
|
| 117 |
video_a_output = gr.Textbox(label="Resposta do Analista de Vídeo", interactive=False, lines=3)
|
| 118 |
-
|
| 119 |
with gr.Blocks():
|
| 120 |
-
gr.Markdown("---")
|
| 121 |
-
gr.Markdown("### Analisar as Imagens de Referência")
|
| 122 |
image_q_input = gr.Textbox(label="Faça uma pergunta sobre TODAS as imagens de referência", placeholder="Ex: Há texto visível em alguma das imagens?")
|
| 123 |
image_q_button = gr.Button("Perguntar às Imagens")
|
| 124 |
image_a_output = gr.Textbox(label="Respostas do Analista de Imagens", interactive=False, lines=5)
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
update_log_button = gr.Button(...)
|
| 130 |
|
| 131 |
# --- 4. CONEXÕES DE EVENTOS ---
|
| 132 |
-
|
| 133 |
-
storyboard_and_keyframes_button.click(
|
| 134 |
-
fn=run_pre_production_wrapper,
|
| 135 |
-
inputs=[prompt_input, num_keyframes_slider, ref_files, resolution_selector, duration_per_fragment_slider],
|
| 136 |
-
outputs=[generation_state_holder, storyboard_output, keyframe_gallery, step3_accordion, reference_images_state]
|
| 137 |
-
)
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
)
|
| 147 |
|
| 148 |
-
image_q_button.click(
|
| 149 |
-
fn=answer_images_wrapper,
|
| 150 |
-
inputs=[reference_images_state, image_q_input],
|
| 151 |
-
outputs=[image_a_output]
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
-
update_log_button.click(fn=get_log_content, inputs=[], outputs=[log_display])
|
| 155 |
generation_state_holder.change(fn=lambda state: state, inputs=generation_state_holder, outputs=generation_data_output)
|
|
|
|
| 156 |
|
| 157 |
# --- 5. INICIALIZAÇÃO DA APLICAÇÃO ---
|
| 158 |
if __name__ == "__main__":
|
|
|
|
| 4 |
#
|
| 5 |
# Versão 6.1.0 (UI with Integrated VQA Testing)
|
| 6 |
#
|
| 7 |
+
# Esta versão implementa a interface de usuário final, com um layout de coluna única,
|
| 8 |
+
# streaming de resultados, visualizador de logs e uma seção de testes para o
|
| 9 |
+
# especialista de Visão Computacional (VQA).
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
import yaml
|
|
|
|
| 20 |
# --- 1. IMPORTAÇÕES DO FRAMEWORK ---
|
| 21 |
import aduc_framework
|
| 22 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
|
|
|
| 23 |
from aduc_framework.managers.vision_qa_manager import vision_qa_manager_singleton
|
| 24 |
|
| 25 |
+
# --- CONFIGURAÇÃO DE TEMA E LOGGING ---
|
| 26 |
+
cinematic_theme = gr.themes.Base(
|
| 27 |
+
primary_hue=gr.themes.colors.indigo,
|
| 28 |
+
secondary_hue=gr.themes.colors.purple,
|
| 29 |
+
neutral_hue=gr.themes.colors.slate,
|
| 30 |
+
font=(gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"),
|
| 31 |
+
).set(
|
| 32 |
+
body_background_fill="#111827", body_text_color="#E5E7EB",
|
| 33 |
+
button_primary_background_fill="linear-gradient(90deg, #4F46E5, #8B5CF6)",
|
| 34 |
+
button_primary_text_color="#FFFFFF", button_secondary_background_fill="#374151",
|
| 35 |
+
button_secondary_border_color="#4B5563", button_secondary_text_color="#E5E7EB",
|
| 36 |
+
block_background_fill="#1F2937", block_border_width="1px", block_border_color="#374151",
|
| 37 |
+
block_label_background_fill="#374151", block_label_text_color="#E5E7EB",
|
| 38 |
+
block_title_text_color="#FFFFFF", input_background_fill="#374151",
|
| 39 |
+
input_border_color="#4B5563", input_placeholder_color="#9CA3AF",
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
LOG_FILE_PATH = "aduc_log.txt"
|
| 43 |
+
if os.path.exists(LOG_FILE_PATH):
|
| 44 |
+
os.remove(LOG_FILE_PATH)
|
| 45 |
+
|
| 46 |
+
log_format = '%(asctime)s - %(levelname)s - [%(name)s:%(funcName)s] - %(message)s'
|
| 47 |
+
root_logger = logging.getLogger()
|
| 48 |
+
root_logger.setLevel(logging.INFO)
|
| 49 |
+
root_logger.handlers.clear()
|
| 50 |
+
stream_handler = logging.StreamHandler(sys.stdout)
|
| 51 |
+
stream_handler.setFormatter(logging.Formatter(log_format))
|
| 52 |
+
root_logger.addHandler(stream_handler)
|
| 53 |
+
file_handler = logging.FileHandler(LOG_FILE_PATH, mode='w', encoding='utf-8')
|
| 54 |
+
file_handler.setFormatter(logging.Formatter(log_format))
|
| 55 |
+
root_logger.addHandler(file_handler)
|
| 56 |
+
logger = logging.getLogger(__name__)
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
with open("config.yaml", 'r') as f: config = yaml.safe_load(f)
|
| 60 |
+
WORKSPACE_DIR = config['application']['workspace_dir']
|
| 61 |
+
aduc = aduc_framework.create_aduc_instance(workspace_dir=WORKSPACE_DIR)
|
| 62 |
+
logger.info("Interface Gradio inicializada e conectada ao Aduc Framework.")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
logger.critical(f"ERRO CRÍTICO durante a inicialização: {e}", exc_info=True)
|
| 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.")
|
| 68 |
+
gr.Textbox(value=str(e), label="Detalhes do Erro", lines=10)
|
| 69 |
+
demo.launch()
|
| 70 |
+
exit()
|
| 71 |
|
| 72 |
# --- 2. FUNÇÕES WRAPPER (UI <-> FRAMEWORK) ---
|
| 73 |
|
|
|
|
| 74 |
def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str, duration_per_fragment, progress=gr.Progress()):
|
| 75 |
if not ref_files: raise gr.Error("Por favor, forneça pelo menos uma imagem de referência.")
|
| 76 |
|
|
|
|
| 79 |
|
| 80 |
params = PreProductionParams(prompt=prompt, num_keyframes=int(num_keyframes), ref_paths=ref_paths, resolution=target_resolution, duration_per_fragment=duration_per_fragment)
|
| 81 |
|
|
|
|
| 82 |
yield { reference_images_state: ref_paths }
|
| 83 |
|
| 84 |
final_result = {}
|
|
|
|
| 95 |
step3_accordion: gr.update(visible=True, open=True)
|
| 96 |
}
|
| 97 |
|
| 98 |
+
def run_original_production_wrapper(current_state_dict, trim_percent, handler_strength, dest_strength, guidance_scale, stg_scale, steps, progress=gr.Progress()):
|
| 99 |
+
yield {final_video_output: gr.update(value=None, visible=True, label="🎬 Produzindo seu filme...")}
|
| 100 |
+
production_params = ProductionParams(trim_percent=int(trim_percent), handler_strength=handler_strength, destination_convergence_strength=dest_strength, guidance_scale=guidance_scale, stg_scale=stg_scale, inference_steps=int(steps))
|
| 101 |
+
final_video_path, latent_paths, updated_state = aduc.task_produce_original_movie(params=production_params, progress_callback=progress)
|
| 102 |
+
|
| 103 |
+
yield {
|
| 104 |
+
final_video_output: gr.update(value=final_video_path, label="✅ Filme Original Master"),
|
| 105 |
+
step4_accordion: gr.update(visible=True, open=True),
|
| 106 |
+
original_latents_paths_state: latent_paths,
|
| 107 |
+
current_source_video_state: final_video_path,
|
| 108 |
+
generation_state_holder: updated_state.model_dump(),
|
| 109 |
+
}
|
| 110 |
|
| 111 |
+
def run_upscaler_wrapper(source_video, latent_paths, chunk_size, progress=gr.Progress()):
|
| 112 |
+
if not source_video or not latent_paths: raise gr.Error("Fonte de vídeo ou latentes originais não encontrados para o Upscaler.")
|
| 113 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Upscaler Latente...")}
|
| 114 |
+
|
| 115 |
+
final_path = source_video
|
| 116 |
+
for update in aduc.task_run_latent_upscaler(latent_paths, int(chunk_size), progress):
|
| 117 |
+
if "final_path" in update: final_path = update['final_path']
|
| 118 |
|
| 119 |
+
yield {
|
| 120 |
+
final_video_output: gr.update(value=final_path, label="✅ Upscale Latente Concluído"),
|
| 121 |
+
current_source_video_state: final_path
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
def run_hd_wrapper(source_video, steps, global_prompt, progress=gr.Progress()):
|
| 125 |
+
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Masterização HD.")
|
| 126 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Masterização HD...")}
|
| 127 |
+
|
| 128 |
+
final_path = source_video
|
| 129 |
+
for update in aduc.task_run_hd_mastering(source_video, int(steps), global_prompt, progress):
|
| 130 |
+
if "final_path" in update: final_path = update['final_path']
|
| 131 |
+
|
| 132 |
+
yield {
|
| 133 |
+
final_video_output: gr.update(value=final_path, label="✅ Masterização HD Concluída"),
|
| 134 |
+
current_source_video_state: final_path
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
def run_audio_wrapper(source_video, audio_prompt, global_prompt, progress=gr.Progress()):
|
| 138 |
+
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Geração de Áudio.")
|
| 139 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Geração de Áudio...")}
|
| 140 |
|
| 141 |
+
final_audio_prompt = audio_prompt if audio_prompt and audio_prompt.strip() else global_prompt
|
| 142 |
+
final_path = source_video
|
| 143 |
+
for update in aduc.task_run_audio_generation(source_video, final_audio_prompt, progress):
|
| 144 |
+
if "final_path" in update: final_path = update['final_path']
|
| 145 |
+
|
| 146 |
+
yield {final_video_output: gr.update(value=final_path, label="✅ Filme Final com Áudio")}
|
| 147 |
+
|
| 148 |
+
def answer_video_wrapper(source_video, question):
|
| 149 |
+
if not source_video: raise gr.Error("Nenhum vídeo final foi gerado para ser analisado.")
|
| 150 |
+
if not question or not question.strip(): raise gr.Error("Por favor, digite uma pergunta.")
|
| 151 |
+
yield "Analisando o vídeo... (Isso pode levar um momento)"
|
| 152 |
answer = vision_qa_manager_singleton.answer_on_video(video_path=source_video, question=question)
|
| 153 |
yield answer
|
| 154 |
|
| 155 |
def answer_images_wrapper(image_paths, question):
|
| 156 |
+
if not image_paths: raise gr.Error("Nenhuma imagem de referência foi carregada para ser analisada.")
|
| 157 |
+
if not question or not question.strip(): raise gr.Error("Por favor, digite uma pergunta.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
yield "Analisando as imagens de referência..."
|
| 159 |
+
all_answers = [f"--- Imagem {i+1} ---\nResposta: {vision_qa_manager_singleton.answer_on_image(path, question)}\n" for i, path in enumerate(image_paths)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
yield "\n".join(all_answers)
|
| 161 |
|
| 162 |
def get_log_content():
|
|
|
|
| 166 |
|
| 167 |
# --- 3. DEFINIÇÃO DA UI ---
|
| 168 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
| 169 |
+
# Estados para gerenciar os dados nos bastidores
|
| 170 |
generation_state_holder = gr.State(value={})
|
| 171 |
original_latents_paths_state = gr.State(value=[])
|
| 172 |
current_source_video_state = gr.State(value=None)
|
| 173 |
+
reference_images_state = gr.State(value=[])
|
| 174 |
|
| 175 |
gr.Markdown("<h1>ADUC-SDR 🎬 - O Diretor de Cinema IA</h1>")
|
| 176 |
+
gr.Markdown("<p>Crie um filme completo com vídeo e áudio, orquestrado por uma equipe de IAs especialistas.</p>")
|
| 177 |
+
|
| 178 |
+
with gr.Accordion("Etapa 1: Roteiro e Cenas-Chave (Pré-Produção)", open=True) as step1_accordion:
|
| 179 |
+
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.")
|
| 180 |
+
with gr.Row():
|
| 181 |
+
lang_selector = gr.Radio(["🇧🇷", "🇺🇸", "🇨🇳"], value="🇧🇷", label="Idioma / Language")
|
| 182 |
+
resolution_selector = gr.Radio(["512x512", "768x768", "1024x1024"], value="512x512", label="Resolução Base")
|
| 183 |
+
ref_image_input = gr.File(label="Grupo de Imagens do Usuário", file_count="multiple", file_types=["image"])
|
| 184 |
+
with gr.Row():
|
| 185 |
+
num_keyframes_slider = gr.Slider(minimum=2, maximum=42, value=4, step=2, label="Número de Cenas-Chave (Par)")
|
| 186 |
+
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)
|
| 187 |
+
storyboard_and_keyframes_button = gr.Button("Gerar Roteiro e Keyframes", variant="primary")
|
| 188 |
+
|
| 189 |
+
with gr.Accordion("Etapa 2: Produção do Vídeo Original", open=False, visible=False) as step3_accordion:
|
| 190 |
+
trim_percent_slider = gr.Slider(minimum=10, maximum=90, value=50, step=5, label="Poda Causal (%)")
|
| 191 |
+
handler_strength = gr.Slider(label="Força do Déjà-Vu", minimum=0.0, maximum=1.0, value=0.5, step=0.05)
|
| 192 |
+
dest_strength = gr.Slider(label="Força da Âncora Final", minimum=0.0, maximum=1.0, value=0.75, step=0.05)
|
| 193 |
+
guidance_scale_slider = gr.Slider(minimum=1.0, maximum=10.0, value=2.0, step=0.1, label="Escala de Orientação")
|
| 194 |
+
stg_scale_slider = gr.Slider(minimum=0.0, maximum=1.0, value=0.025, step=0.005, label="Escala STG")
|
| 195 |
+
inference_steps_slider = gr.Slider(minimum=10, maximum=50, value=20, step=1, label="Passos de Inferência")
|
| 196 |
+
produce_original_button = gr.Button("🎬 Produzir Vídeo Original", variant="primary")
|
| 197 |
+
|
| 198 |
+
with gr.Accordion("Etapa 3: Pós-Produção (Opcional)", open=False, visible=False) as step4_accordion:
|
| 199 |
+
gr.Markdown("Aplique melhorias ao filme. Cada etapa usa o resultado da anterior como fonte.")
|
| 200 |
+
with gr.Accordion("A. Upscaler Latente 2x", open=True):
|
| 201 |
+
upscaler_chunk_size_slider = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="Fragmentos por Lote")
|
| 202 |
+
run_upscaler_button = gr.Button("Executar Upscaler Latente", variant="secondary")
|
| 203 |
+
with gr.Accordion("B. Masterização HD (SeedVR)", open=True):
|
| 204 |
+
hd_steps_slider = gr.Slider(minimum=20, maximum=150, value=100, step=5, label="Passos de Inferência HD")
|
| 205 |
+
run_hd_button = gr.Button("Executar Masterização HD", variant="secondary")
|
| 206 |
+
with gr.Accordion("C. Geração de Áudio", open=True):
|
| 207 |
+
audio_prompt_input = gr.Textbox(label="Prompt de Áudio Detalhado (Opcional)", lines=2, placeholder="Descreva os sons, efeitos e música.")
|
| 208 |
+
run_audio_button = gr.Button("Gerar Áudio", variant="secondary")
|
| 209 |
+
|
| 210 |
+
final_video_output = gr.Video(label="Filme Final (Resultado da Última Etapa)", visible=False, interactive=False)
|
| 211 |
|
| 212 |
+
with gr.Accordion("Grupo das Keyframes", open=False) as keyframes_accordion:
|
| 213 |
+
keyframe_gallery = gr.Gallery(label="Keyframes Gerados", visible=True, object_fit="contain", height="auto", type="filepath")
|
| 214 |
+
|
| 215 |
+
with gr.Accordion("🧬 DNA Digital da Geração (JSON)", open=False) as data_accordion:
|
| 216 |
+
storyboard_output = gr.JSON(label="Roteiro Gerado (Storyboard)")
|
| 217 |
+
generation_data_output = gr.JSON(label="Estado de Geração Completo")
|
| 218 |
+
|
|
|
|
|
|
|
| 219 |
with gr.Accordion("🧪 Etapa de Análise Visual (VQA - Teste)", open=False) as vqa_accordion:
|
| 220 |
with gr.Blocks():
|
| 221 |
gr.Markdown("### Analisar o Vídeo Final")
|
| 222 |
video_q_input = gr.Textbox(label="Faça uma pergunta sobre o vídeo gerado", placeholder="Ex: O leão chega a beber água?")
|
| 223 |
video_q_button = gr.Button("Perguntar ao Vídeo")
|
| 224 |
video_a_output = gr.Textbox(label="Resposta do Analista de Vídeo", interactive=False, lines=3)
|
|
|
|
| 225 |
with gr.Blocks():
|
| 226 |
+
gr.Markdown("---"); gr.Markdown("### Analisar as Imagens de Referência")
|
|
|
|
| 227 |
image_q_input = gr.Textbox(label="Faça uma pergunta sobre TODAS as imagens de referência", placeholder="Ex: Há texto visível em alguma das imagens?")
|
| 228 |
image_q_button = gr.Button("Perguntar às Imagens")
|
| 229 |
image_a_output = gr.Textbox(label="Respostas do Analista de Imagens", interactive=False, lines=5)
|
| 230 |
|
| 231 |
+
with gr.Accordion("📝 Log de Geração (Detalhado)", open=False) as log_accordion:
|
| 232 |
+
log_display = gr.Textbox(label="Log da Sessão", lines=20, interactive=False, autoscroll=True)
|
| 233 |
+
update_log_button = gr.Button("Atualizar Log")
|
|
|
|
| 234 |
|
| 235 |
# --- 4. CONEXÕES DE EVENTOS ---
|
| 236 |
+
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, reference_images_state])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
+
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=[final_video_output, step4_accordion, original_latents_paths_state, current_source_video_state, generation_state_holder])
|
| 239 |
|
| 240 |
+
run_upscaler_button.click(fn=run_upscaler_wrapper, inputs=[current_source_video_state, original_latents_paths_state, upscaler_chunk_size_slider], outputs=[final_video_output, current_source_video_state])
|
| 241 |
+
run_hd_button.click(fn=run_hd_wrapper, inputs=[current_source_video_state, hd_steps_slider, prompt_input], outputs=[final_video_output, current_source_video_state])
|
| 242 |
+
run_audio_button.click(fn=run_audio_wrapper, inputs=[current_source_video_state, audio_prompt_input, prompt_input], outputs=[final_video_output])
|
| 243 |
+
|
| 244 |
+
video_q_button.click(fn=answer_video_wrapper, inputs=[current_source_video_state, video_q_input], outputs=[video_a_output])
|
| 245 |
+
image_q_button.click(fn=answer_images_wrapper, inputs=[reference_images_state, image_q_input], outputs=[image_a_output])
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
generation_state_holder.change(fn=lambda state: state, inputs=generation_state_holder, outputs=generation_data_output)
|
| 248 |
+
update_log_button.click(fn=get_log_content, inputs=[], outputs=[log_display])
|
| 249 |
|
| 250 |
# --- 5. INICIALIZAÇÃO DA APLICAÇÃO ---
|
| 251 |
if __name__ == "__main__":
|