Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@
|
|
| 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,
|
|
|
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
import yaml
|
|
@@ -20,189 +21,206 @@ import json
|
|
| 20 |
import aduc_framework
|
| 21 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
| 22 |
|
| 23 |
-
# Configuração
|
| 24 |
-
cinematic_theme = gr.themes.Base(
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
LOG_FILE_PATH = "aduc_log.txt"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {
|
| 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,
|
| 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 {
|
| 55 |
|
| 56 |
-
final_path =
|
| 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
|
| 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 {
|
| 68 |
|
| 69 |
-
final_path =
|
| 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
|
| 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 {
|
| 81 |
|
| 82 |
final_audio_prompt = audio_prompt if audio_prompt and audio_prompt.strip() else global_prompt
|
| 83 |
-
final_path =
|
| 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 |
-
|
| 96 |
-
except FileNotFoundError:
|
| 97 |
-
return "Arquivo de log ainda não criado."
|
| 98 |
|
| 99 |
-
# --- 3. DEFINIÇÃO DA
|
| 100 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
| 101 |
-
#
|
| 102 |
generation_state_holder = gr.State(value={})
|
| 103 |
original_latents_paths_state = gr.State(value=[])
|
| 104 |
-
current_source_video_state = gr.State(value=None)
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 145 |
run_audio_button = gr.Button("Gerar Áudio", variant="secondary")
|
| 146 |
|
| 147 |
-
# ---
|
| 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 |
-
|
| 153 |
-
|
| 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
|
| 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 |
-
|
| 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 |
-
|
| 200 |
-
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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, streaming de resultados e
|
| 9 |
+
# um visualizador de logs em tempo real, alinhado com a arquitetura do Diretor Autônomo.
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
import yaml
|
|
|
|
| 21 |
import aduc_framework
|
| 22 |
from aduc_framework.types import PreProductionParams, ProductionParams
|
| 23 |
|
| 24 |
+
# Configuração de Tema Cinemático
|
| 25 |
+
cinematic_theme = gr.themes.Base(
|
| 26 |
+
primary_hue=gr.themes.colors.indigo,
|
| 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 |
+
# Configuração de Logging
|
| 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 |
+
# Inicialização do Aduc Framework
|
| 59 |
+
try:
|
| 60 |
+
with open("config.yaml", 'r') as f: config = yaml.safe_load(f)
|
| 61 |
+
WORKSPACE_DIR = config['application']['workspace_dir']
|
| 62 |
+
aduc = aduc_framework.create_aduc_instance(workspace_dir=WORKSPACE_DIR)
|
| 63 |
+
logger.info("Interface Gradio inicializada e conectada ao Aduc Framework.")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.critical(f"ERRO CRÍTICO durante a inicialização: {e}", exc_info=True)
|
| 66 |
+
with gr.Blocks() as demo:
|
| 67 |
+
gr.Markdown("# ERRO CRÍTICO NA INICIALIZAÇÃO")
|
| 68 |
+
gr.Markdown("Não foi possível iniciar o Aduc Framework. Verifique os logs para mais detalhes.")
|
| 69 |
+
gr.Textbox(value=str(e), label="Detalhes do Erro", lines=10)
|
| 70 |
+
demo.launch()
|
| 71 |
+
exit()
|
| 72 |
+
|
| 73 |
+
# --- 2. FUNÇÕES WRAPPER (UI <-> FRAMEWORK) ---
|
| 74 |
|
|
|
|
| 75 |
def run_pre_production_wrapper(prompt, num_keyframes, ref_files, resolution_str, duration_per_fragment, progress=gr.Progress()):
|
| 76 |
+
if not ref_files: raise gr.Error("Por favor, forneça pelo menos uma imagem de referência.")
|
| 77 |
+
|
| 78 |
+
target_resolution = int(resolution_str.split('x')[0])
|
| 79 |
+
ref_paths = [aduc.process_image_for_story(f.name, target_resolution, f"ref_processed_{i}.png") for i, f in enumerate(ref_files)]
|
| 80 |
+
|
| 81 |
+
params = PreProductionParams(prompt=prompt, num_keyframes=int(num_keyframes), ref_paths=ref_paths, resolution=target_resolution, duration_per_fragment=duration_per_fragment)
|
| 82 |
+
|
| 83 |
+
final_result = {}
|
| 84 |
+
for update in aduc.task_pre_production(params, progress):
|
| 85 |
+
yield {
|
| 86 |
+
generation_state_holder: update.get("updated_state", gr.UNCHANGED),
|
| 87 |
+
storyboard_output: update.get("storyboard", gr.UNCHANGED),
|
| 88 |
+
keyframe_gallery: gr.update(value=update.get("final_keyframes", [])),
|
| 89 |
+
}
|
| 90 |
+
final_result = update
|
| 91 |
+
|
| 92 |
+
yield {
|
| 93 |
+
generation_state_holder: final_result.get("updated_state"),
|
| 94 |
+
step3_accordion: gr.update(visible=True, open=True)
|
| 95 |
+
}
|
| 96 |
|
|
|
|
| 97 |
def run_original_production_wrapper(current_state_dict, trim_percent, handler_strength, dest_strength, guidance_scale, stg_scale, steps, progress=gr.Progress()):
|
| 98 |
+
yield {final_video_output: gr.update(value=None, visible=True, label="🎬 Produzindo seu filme...")}
|
| 99 |
+
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))
|
|
|
|
| 100 |
final_video_path, latent_paths, updated_state = aduc.task_produce_original_movie(params=production_params, progress_callback=progress)
|
| 101 |
|
| 102 |
yield {
|
| 103 |
final_video_output: gr.update(value=final_video_path, label="✅ Filme Original Master"),
|
| 104 |
step4_accordion: gr.update(visible=True, open=True),
|
| 105 |
original_latents_paths_state: latent_paths,
|
| 106 |
+
current_source_video_state: final_video_path,
|
| 107 |
generation_state_holder: updated_state.model_dump(),
|
|
|
|
| 108 |
}
|
| 109 |
|
| 110 |
def run_upscaler_wrapper(source_video, latent_paths, chunk_size, progress=gr.Progress()):
|
| 111 |
if not source_video or not latent_paths: raise gr.Error("Fonte de vídeo ou latentes originais não encontrados para o Upscaler.")
|
| 112 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Upscaler Latente...")}
|
| 113 |
|
| 114 |
+
final_path = source_video
|
| 115 |
for update in aduc.task_run_latent_upscaler(latent_paths, int(chunk_size), progress):
|
| 116 |
if "final_path" in update: final_path = update['final_path']
|
| 117 |
|
| 118 |
yield {
|
| 119 |
final_video_output: gr.update(value=final_path, label="✅ Upscale Latente Concluído"),
|
| 120 |
+
current_source_video_state: final_path
|
| 121 |
}
|
| 122 |
|
| 123 |
def run_hd_wrapper(source_video, steps, global_prompt, progress=gr.Progress()):
|
| 124 |
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Masterização HD.")
|
| 125 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Masterização HD...")}
|
| 126 |
|
| 127 |
+
final_path = source_video
|
| 128 |
for update in aduc.task_run_hd_mastering(source_video, int(steps), global_prompt, progress):
|
| 129 |
if "final_path" in update: final_path = update['final_path']
|
| 130 |
|
| 131 |
yield {
|
| 132 |
final_video_output: gr.update(value=final_path, label="✅ Masterização HD Concluída"),
|
| 133 |
+
current_source_video_state: final_path
|
| 134 |
}
|
| 135 |
|
| 136 |
def run_audio_wrapper(source_video, audio_prompt, global_prompt, progress=gr.Progress()):
|
| 137 |
if not source_video: raise gr.Error("Fonte de vídeo não encontrada para a Geração de Áudio.")
|
| 138 |
+
yield {final_video_output: gr.update(label="Pós-Produção: Geração de Áudio...")}
|
| 139 |
|
| 140 |
final_audio_prompt = audio_prompt if audio_prompt and audio_prompt.strip() else global_prompt
|
| 141 |
+
final_path = source_video
|
| 142 |
for update in aduc.task_run_audio_generation(source_video, final_audio_prompt, progress):
|
| 143 |
if "final_path" in update: final_path = update['final_path']
|
| 144 |
|
| 145 |
+
yield {final_video_output: gr.update(value=final_path, label="✅ Filme Final com Áudio")}
|
|
|
|
|
|
|
| 146 |
|
|
|
|
| 147 |
def get_log_content():
|
| 148 |
try:
|
| 149 |
+
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f: return f.read()
|
| 150 |
+
except FileNotFoundError: return "Arquivo de log ainda não criado."
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
# --- 3. DEFINIÇÃO DA UI ---
|
| 153 |
with gr.Blocks(theme=cinematic_theme, css="style.css") as demo:
|
| 154 |
+
# Estados para gerenciar os caminhos dos vídeos nos bastidores
|
| 155 |
generation_state_holder = gr.State(value={})
|
| 156 |
original_latents_paths_state = gr.State(value=[])
|
| 157 |
+
current_source_video_state = gr.State(value=None)
|
| 158 |
|
| 159 |
gr.Markdown("<h1>ADUC-SDR 🎬 - O Diretor de Cinema IA</h1>")
|
| 160 |
gr.Markdown("<p>Crie um filme completo com vídeo e áudio, orquestrado por uma equipe de IAs especialistas.</p>")
|
| 161 |
|
|
|
|
| 162 |
with gr.Accordion("Etapa 1: Roteiro e Cenas-Chave (Pré-Produção)", open=True) as step1_accordion:
|
| 163 |
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.")
|
|
|
|
| 164 |
with gr.Row():
|
| 165 |
lang_selector = gr.Radio(["🇧🇷", "🇺🇸", "🇨🇳"], value="🇧🇷", label="Idioma / Language")
|
| 166 |
resolution_selector = gr.Radio(["512x512", "768x768", "1024x1024"], value="512x512", label="Resolução Base")
|
| 167 |
+
ref_image_input = gr.File(label="Grupo de Imagens do Usuário", file_count="multiple", file_types=["image"])
|
|
|
|
|
|
|
|
|
|
| 168 |
with gr.Row():
|
| 169 |
num_keyframes_slider = gr.Slider(minimum=2, maximum=42, value=4, step=2, label="Número de Cenas-Chave (Par)")
|
| 170 |
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)
|
|
|
|
| 171 |
storyboard_and_keyframes_button = gr.Button("Gerar Roteiro e Keyframes", variant="primary")
|
| 172 |
+
|
|
|
|
| 173 |
with gr.Accordion("Etapa 2: Produção do Vídeo Original", open=False, visible=False) as step3_accordion:
|
| 174 |
+
trim_percent_slider = gr.Slider(minimum=10, maximum=90, value=50, step=5, label="Poda Causal (%)")
|
| 175 |
+
handler_strength = gr.Slider(label="Força do Déjà-Vu", minimum=0.0, maximum=1.0, value=0.5, step=0.05)
|
| 176 |
+
dest_strength = gr.Slider(label="Força da Âncora Final", minimum=0.0, maximum=1.0, value=0.75, step=0.05)
|
| 177 |
+
guidance_scale_slider = gr.Slider(minimum=1.0, maximum=10.0, value=2.0, step=0.1, label="Escala de Orientação")
|
| 178 |
+
stg_scale_slider = gr.Slider(minimum=0.0, maximum=1.0, value=0.025, step=0.005, label="Escala STG")
|
| 179 |
+
inference_steps_slider = gr.Slider(minimum=10, maximum=50, value=20, step=1, label="Passos de Inferência")
|
| 180 |
produce_original_button = gr.Button("🎬 Produzir Vídeo Original", variant="primary")
|
| 181 |
|
|
|
|
| 182 |
with gr.Accordion("Etapa 3: Pós-Produção (Opcional)", open=False, visible=False) as step4_accordion:
|
| 183 |
gr.Markdown("Aplique melhorias ao filme. Cada etapa usa o resultado da anterior como fonte.")
|
|
|
|
| 184 |
with gr.Accordion("A. Upscaler Latente 2x", open=True):
|
| 185 |
upscaler_chunk_size_slider = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="Fragmentos por Lote")
|
| 186 |
run_upscaler_button = gr.Button("Executar Upscaler Latente", variant="secondary")
|
|
|
|
| 187 |
with gr.Accordion("B. Masterização HD (SeedVR)", open=True):
|
| 188 |
hd_steps_slider = gr.Slider(minimum=20, maximum=150, value=100, step=5, label="Passos de Inferência HD")
|
| 189 |
run_hd_button = gr.Button("Executar Masterização HD", variant="secondary")
|
|
|
|
| 190 |
with gr.Accordion("C. Geração de Áudio", open=True):
|
| 191 |
+
audio_prompt_input = gr.Textbox(label="Prompt de Áudio Detalhado (Opcional)", lines=2, placeholder="Descreva os sons, efeitos e música.")
|
| 192 |
run_audio_button = gr.Button("Gerar Áudio", variant="secondary")
|
| 193 |
|
| 194 |
+
# --- RESULTADOS CONSOLIDADOS ---
|
|
|
|
|
|
|
| 195 |
final_video_output = gr.Video(label="Filme Final (Resultado da Última Etapa)", visible=False, interactive=False)
|
| 196 |
|
| 197 |
+
with gr.Accordion("Grupo das Keyframes", open=False) as keyframes_accordion:
|
| 198 |
+
keyframe_gallery = gr.Gallery(label="Keyframes Gerados", visible=True, object_fit="contain", height="auto", type="filepath")
|
|
|
|
| 199 |
|
|
|
|
| 200 |
with gr.Accordion("🧬 DNA Digital da Geração (JSON)", open=False) as data_accordion:
|
| 201 |
storyboard_output = gr.JSON(label="Roteiro Gerado (Storyboard)")
|
| 202 |
generation_data_output = gr.JSON(label="Estado de Geração Completo")
|
| 203 |
|
|
|
|
| 204 |
with gr.Accordion("📝 Log de Geração (Detalhado)", open=False) as log_accordion:
|
| 205 |
log_display = gr.Textbox(label="Log da Sessão", lines=20, interactive=False, autoscroll=True)
|
| 206 |
update_log_button = gr.Button("Atualizar Log")
|
| 207 |
|
| 208 |
+
# --- 4. CONEXÕES DE EVENTOS ---
|
| 209 |
+
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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
+
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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
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])
|
| 214 |
+
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])
|
| 215 |
+
run_audio_button.click(fn=run_audio_wrapper, inputs=[current_source_video_state, audio_prompt_input, prompt_input], outputs=[final_video_output])
|
| 216 |
|
|
|
|
| 217 |
generation_state_holder.change(fn=lambda state: state, inputs=generation_state_holder, outputs=generation_data_output)
|
| 218 |
+
update_log_button.click(fn=get_log_content, inputs=[], outputs=[log_display])
|
| 219 |
|
| 220 |
# --- 5. INICIALIZAÇÃO DA APLICAÇÃO ---
|
| 221 |
if __name__ == "__main__":
|
| 222 |
+
if os.path.exists(WORKSPACE_DIR):
|
| 223 |
+
shutil.rmtree(WORKSPACE_DIR)
|
| 224 |
+
os.makedirs(WORKSPACE_DIR)
|
| 225 |
+
logger.info("Aplicação Gradio iniciada. Lançando interface...")
|
| 226 |
+
demo.queue().launch()
|