encabezado(“4. Creando una figura de referencia personalizada”) reference_dir = OUTPUT_ROOT / “01_custom_references” reference_dir.mkdir(parents=True, exist_ok=True) reference_path = reference_dir / “reference_architecture_style.png” W, H = 1333, 750 img = Image.new(“RGB”, (W, H), “white”) draw = ImageDraw.Draw(img) intente: title_font = ImageFont.truetype(“DejaVuSans-Bold.ttf”, 36) box_font = ImageFont.truetype(“DejaVuSans-Bold.ttf”, 24) small_font = ImageFont.truetype(“DejaVuSans.ttf”, 18) excepto excepción: title_font = Ninguno box_font = Ninguno small_font = Ninguno draw.text( (W // 2, 55), “Diseño de referencia: Tubería científica modular”, Anchor=”mm”, fill=”black”, font=title_font, ) boxes = [
(90, 215, 290, 120, “Input”, “documents”),
(365, 215, 290, 120, “Planner”, “route by task”),
(640, 215, 290, 120, “Experts”, “summary / table / vision”),
(915, 215, 290, 120, “Verifier”, “grounded output”),
]
para i, (x, y, bw, bh, título, subtítulo) en enumerar (cuadros): draw.rounded_rectangle (
[x, y, x + bw, y + bh]radio=22, relleno=(245, 245, 245), contorno=(20, 20, 20), ancho=3, ) draw.text( (x + bw / 2, y + 45), título, anclaje=”mm”, relleno=”negro”, fuente=box_font, ) draw.text( (x + bw / 2, y + 82), subtítulo, ancla=”mm”, relleno=(70, 70, 70), font=small_font, ) si i < len(boxes) - 1: ax = x + bw + 20 ay = y + bh / 2 bx = boxes[i + 1][0] - 20 por = ay dibujar.línea([ax, ay, bx, by]fill="negro", ancho=5) draw.polygon( [(bx, by), (bx - 18, by - 10), (bx - 18, by + 10)]fill="negro", ) draw.rounded_rectangle( [180, 500, 1150, 585]radio=24, relleno=(252, 252, 252), contorno=(80, 80, 80), ancho=2, ) draw.text( (665, 542), "Indicación de diseño: módulos alineados, etiquetas dispersas, fuerte dirección de flujo, estilo académico limpio", anclaje="mm", relleno=(40, 40, 40), fuente=small_font, ) img.save(reference_path) print(f"Referencia personalizada guardada: {reference_path}") display_file_if_possible(reference_path, "Figura de referencia personalizada") header("5. Configuración de AutoFigure respaldada por API") API_KEY = Collect_api_key(PROVIDER) if not API_KEY: print("No se proporciona clave API. Se omitirán las secciones de generación de nube.") else: print(f"Proveedor: {PROVIDER}") print(f"Modelo de generación: {GENERATION_MODEL}") print("Clave API recibida. La clave no se imprime.") config = Ninguno agente = Ninguno si API_KEY: config = Config( generacion_api_key=API_KEY, generacion_provider=PROVIDER, generacion_model=GENERATION_MODEL, metodologia_api_key=API_KEY, metodologia_provider=PROVIDER, metodologia_model=GENERATION_MODEL, mejora_api_key=API_KEY si RUN_IMAGE_ENHANCEMENT más Ninguno, mejora_provider=PROVIDER, mejora_model=os.environ.get( "AUTOFIGURE_ENHANCEMENT_MODEL", "google/gemini-3.1-flash-image-preview" si PROVIDER == "openrouter" más "gemini-3.1-flash-image-preview",), max_iterations=MAX_ITERACIONES, umbral_calidad=umbral_calidad, dirección_salida=str(ROOT_SALIDA / "02_text_to_figure"), referencias_personalizadas=[str(reference_path)]art_style=ART_STYLE, ) validation_errors = config.validate() print(f"Errores de validación de configuración: {validation_errors if validation_errors else 'none'}") print(f"Referencias encontradas por configuración: {len(config.get_references())}") agente = AutoFigureAgent(config) encabezado("6. Vista previa de plantilla de solicitud") aviso_preview = get_initial_prompt_template( tema="papel", contenido=FIGURE_DESCRIPTION[:2500]formato_salida="svg", ) print(prompt_preview[:2500]) print("\n... vista previa del mensaje truncada ...") if API_KEY y RUN_TEXT_TO_FIGURE: header("7. Ejecución de la generación de texto a figura") text_output_dir = OUTPUT_ROOT / "02_text_to_figure" text_output_dir.mkdir(parents=True, exist_ok=True) text_result = agent.generate( descripción=FIGURE_DESCRIPTION, max_iterations=MAX_ITERACIONES, umbral_calidad=umbral_calidad, formato_salida=TEXT_OUTPUT_FORMAT, enable_enhancement=RUN_IMAGE_ENHANCEMENT, art_style=ART_STYLE, mejora_input_type="code2prompt", mejora_count=1, custom_references=[str(reference_path)]dirección_salida=cadena(dir_salida_texto), tema="papel", ) resumen_generación_resultado(resultado_texto, "Resultado de texto a figura") else: print("Omitir generación de texto a figura.")
(90, 215, 290, 120, “Input”, “documents”),
(365, 215, 290, 120, “Planner”, “route by task”),
(640, 215, 290, 120, “Experts”, “summary / table / vision”),
(915, 215, 290, 120, “Verifier”, “grounded output”),
]
para i, (x, y, bw, bh, título, subtítulo) en enumerar (cuadros): draw.rounded_rectangle (
[x, y, x + bw, y + bh]radio=22, relleno=(245, 245, 245), contorno=(20, 20, 20), ancho=3, ) draw.text( (x + bw / 2, y + 45), título, anclaje=”mm”, relleno=”negro”, fuente=box_font, ) draw.text( (x + bw / 2, y + 82), subtítulo, ancla=”mm”, relleno=(70, 70, 70), font=small_font, ) si i < len(boxes) - 1: ax = x + bw + 20 ay = y + bh / 2 bx = boxes[i + 1][0] - 20 por = ay dibujar.línea([ax, ay, bx, by]fill="negro", ancho=5) draw.polygon( [(bx, by), (bx - 18, by - 10), (bx - 18, by + 10)]fill="negro", ) draw.rounded_rectangle( [180, 500, 1150, 585]radio=24, relleno=(252, 252, 252), contorno=(80, 80, 80), ancho=2, ) draw.text( (665, 542), "Indicación de diseño: módulos alineados, etiquetas dispersas, fuerte dirección de flujo, estilo académico limpio", anclaje="mm", relleno=(40, 40, 40), fuente=small_font, ) img.save(reference_path) print(f"Referencia personalizada guardada: {reference_path}") display_file_if_possible(reference_path, "Figura de referencia personalizada") header("5. Configuración de AutoFigure respaldada por API") API_KEY = Collect_api_key(PROVIDER) if not API_KEY: print("No se proporciona clave API. Se omitirán las secciones de generación de nube.") else: print(f"Proveedor: {PROVIDER}") print(f"Modelo de generación: {GENERATION_MODEL}") print("Clave API recibida. La clave no se imprime.") config = Ninguno agente = Ninguno si API_KEY: config = Config( generacion_api_key=API_KEY, generacion_provider=PROVIDER, generacion_model=GENERATION_MODEL, metodologia_api_key=API_KEY, metodologia_provider=PROVIDER, metodologia_model=GENERATION_MODEL, mejora_api_key=API_KEY si RUN_IMAGE_ENHANCEMENT más Ninguno, mejora_provider=PROVIDER, mejora_model=os.environ.get( "AUTOFIGURE_ENHANCEMENT_MODEL", "google/gemini-3.1-flash-image-preview" si PROVIDER == "openrouter" más "gemini-3.1-flash-image-preview",), max_iterations=MAX_ITERACIONES, umbral_calidad=umbral_calidad, dirección_salida=str(ROOT_SALIDA / "02_text_to_figure"), referencias_personalizadas=[str(reference_path)]art_style=ART_STYLE, ) validation_errors = config.validate() print(f"Errores de validación de configuración: {validation_errors if validation_errors else 'none'}") print(f"Referencias encontradas por configuración: {len(config.get_references())}") agente = AutoFigureAgent(config) encabezado("6. Vista previa de plantilla de solicitud") aviso_preview = get_initial_prompt_template( tema="papel", contenido=FIGURE_DESCRIPTION[:2500]formato_salida="svg", ) print(prompt_preview[:2500]) print("\n... vista previa del mensaje truncada ...") if API_KEY y RUN_TEXT_TO_FIGURE: header("7. Ejecución de la generación de texto a figura") text_output_dir = OUTPUT_ROOT / "02_text_to_figure" text_output_dir.mkdir(parents=True, exist_ok=True) text_result = agent.generate( descripción=FIGURE_DESCRIPTION, max_iterations=MAX_ITERACIONES, umbral_calidad=umbral_calidad, formato_salida=TEXT_OUTPUT_FORMAT, enable_enhancement=RUN_IMAGE_ENHANCEMENT, art_style=ART_STYLE, mejora_input_type="code2prompt", mejora_count=1, custom_references=[str(reference_path)]dirección_salida=cadena(dir_salida_texto), tema="papel", ) resumen_generación_resultado(resultado_texto, "Resultado de texto a figura") else: print("Omitir generación de texto a figura.")