|

Building Agentic Document Intelligence Pipelines: Creating Scientific Figures with AutoFigure

In this tutorial, we discover AutoFigure as a sensible toolkit for producing scientific figures straight from textual content descriptions, paper-like content material, and structured methodological explanations. In this tutorial, we arrange the whole AutoFigure setting, repair dependency points reminiscent of Pillow compatibility, and put together the required rendering instruments for SVG and PNG outputs. We then construct a customized reference determine, configure an API-backed era workflow, and use AutoFigure to transform an in depth agentic doc intelligence pipeline right into a publication-style scientific diagram. Along the way in which, we additionally check offline SVG rendering, examine the generated information, create a pattern paper and PDF, and export the ultimate outputs to a reusable gallery and a zipper archive.

import os
import sys
import json
import time
import glob
import shutil
import textwrap
import subprocess
import importlib
from pathlib import Path
from getpass import getpass
REPO_URL = "https://github.com/ResearAI/AutoFigure.git"
REPO_DIR = Path("/content material/AutoFigure")
OUTPUT_ROOT = Path("/content material/autofigure_colab_outputs")
PROVIDER = os.environ.get("AUTOFIGURE_PROVIDER", "openrouter")
DEFAULT_MODELS = {
   "openrouter": "google/gemini-3.1-pro-preview",
   "gemini": "gemini-3.1-pro-preview",
   "bianxie": "gemini-3.1-pro-preview",
}
GENERATION_MODEL = os.environ.get(
   "AUTOFIGURE_MODEL",
   DEFAULT_MODELS.get(PROVIDER, "google/gemini-3.1-pro-preview")
)
MAX_ITERATIONS = int(os.environ.get("AUTOFIGURE_MAX_ITERATIONS", "1"))
QUALITY_THRESHOLD = float(os.environ.get("AUTOFIGURE_QUALITY_THRESHOLD", "8.5"))
RUN_TEXT_TO_FIGURE = True
RUN_PAPER_TO_FIGURE = False
RUN_MXGRAPH_DEMO = False
RUN_IMAGE_ENHANCEMENT = False
TEXT_OUTPUT_FORMAT = "svg"
MXGRAPH_OUTPUT_FORMAT = "mxgraphxml"
ART_STYLE = (
   "clear publication-ready scientific illustration, exact alignment, refined shadows, "
   "clear educational typography, excessive distinction, minimal muddle"
)
FIGURE_DESCRIPTION = """
Create a publication-ready scientific methodology determine for an agentic long-document intelligence system.
The determine ought to clarify the next pipeline in a left-to-right structure:
1. Long paperwork enter the system. They could also be PDFs, scanned experiences, markdown information, tables, or mixed-layout paperwork.
2. A doc normalization layer extracts uncooked textual content, part hierarchy, tables, figures, and metadata.
3. A routing planner decides whether or not every part ought to go to summarization, area extraction, desk reconstruction, visible evaluation, or quotation grounding.
4. Specialized professional modules course of the routed chunks:
  - Summarizer professional creates hierarchical summaries.
  - Extraction professional returns JSON fields.
  - Table professional reconstructs precise tables.
  - Visual professional describes charts and diagrams.
  - Citation professional hyperlinks claims to proof spans.
5. A low-cost orchestration layer selects smaller or bigger LLMs relying on complexity, confidence, and finances.
6. A verification layer checks schema validity, supply grounding, desk consistency, and confidence.
7. The remaining output is an analyst-ready workspace containing a abstract, extracted fields, precise tables, cited solutions, and audit logs.
Design necessities:
- Use a large 16:9 structure.
- Use clear module containers, arrows, and labels.
- Add small callouts for price management, confidence scoring, and auditability.
- Avoid ornamental muddle.
- Make the circulate comprehensible for a finance or enterprise doc intelligence viewers.
"""
MINI_PAPER_MARKDOWN = """
# Efficient Agentic Document Intelligence for Long Financial Reports
## Abstract
We suggest an agentic doc intelligence structure for extracting summaries, info, tables,
and grounded solutions from lengthy, heterogeneous monetary paperwork.
## Method
Our methodology first normalizes every incoming doc right into a structured doc graph. The graph
comprises part nodes, paragraph nodes, desk nodes, determine nodes, and metadata nodes. A routing
planner assigns every node to a specialised professional in accordance with modality, complexity, and required
output schema.
The system makes use of 5 specialists. The summarization professional produces hierarchical summaries from
section-level chunks. The extraction professional fills strict JSON schemas for entities, dates, dangers,
monetary metrics, and obligations. The desk professional reconstructs precise tables and validates row-column
alignment. The visible professional describes charts and diagrams. The quotation professional maps each generated
declare to supply spans.
A budget-aware orchestration layer selects mannequin dimension dynamically. Simple chunks are processed by
low-cost fashions, whereas complicated chunks are escalated to stronger fashions. A verification layer then
checks schema validity, quotation assist, numerical consistency, and desk integrity. Failed checks are
routed again for restore.
## Experiments
We consider on monetary filings and analyst experiences utilizing extraction accuracy, grounding precision,
desk reconstruction high quality, and whole inference price.
"""
def run(cmd, cwd=None, verify=True, quiet=False):
   print(f"n$ {cmd}")
   course of = subprocess.run(
       cmd,
       shell=True,
       cwd=str(cwd) if cwd else None,
       textual content=True,
       stdout=subprocess.PIPE if quiet else None,
       stderr=subprocess.STDOUT if quiet else None,
   )
   if quiet and course of.stdout:
       print(course of.stdout[-5000:])
   if verify and course of.returncode != 0:
       increase RuntimeError(f"Command failed with exit code {course of.returncode}: {cmd}")
   return course of
def heading(title):
   print("n" + "=" * 100)
   print(title)
   print("=" * 100)
def safe_read(path, max_chars=2500):
   path = Path(path)
   if not path.exists():
       return ""
   textual content = path.read_text(encoding="utf-8", errors="ignore")
   return textual content[:max_chars] + ("n... [truncated]" if len(textual content) > max_chars else "")
def clear_loaded_modules(prefixes):
   for identify in listing(sys.modules):
       if any(identify == prefix or identify.startswith(prefix + ".") for prefix in prefixes):
           del sys.modules[name]
def get_colab_secret(names):
   attempt:
       from google.colab import userdata
       for identify in names:
           attempt:
               worth = userdata.get(identify)
               if worth:
                   return worth
           besides Exception:
               cross
   besides Exception:
       cross
   return None
def collect_api_key(supplier):
   env_candidates = [
       "AUTOFIGURE_API_KEY",
       "OPENROUTER_API_KEY",
       "GOOGLE_API_KEY",
       "GEMINI_API_KEY",
       "BIANXIE_API_KEY",
   ]
   for key_name in env_candidates:
       worth = os.environ.get(key_name)
       if worth:
           print(f"Using API key from setting variable: {key_name}")
           return worth
   secret_candidates = {
       "openrouter": ["AUTOFIGURE_API_KEY", "OPENROUTER_API_KEY"],
       "gemini": ["AUTOFIGURE_API_KEY", "GOOGLE_API_KEY", "GEMINI_API_KEY"],
       "bianxie": ["AUTOFIGURE_API_KEY", "BIANXIE_API_KEY"],
   }.get(supplier, ["AUTOFIGURE_API_KEY"])
   worth = get_colab_secret(secret_candidates)
   if worth:
       print("Using API key from Colab Secrets.")
       return worth
   worth = getpass(f"Paste your {supplier} API key, or press Enter to skip cloud era: ").strip()
   return worth

We start by importing and defining the primary paths, supplier settings, mannequin configuration, and tutorial choices. We additionally put together the detailed determine description and pattern paper content material that we use later for AutoFigure era. We then create helper capabilities to run instructions, print part headings, learn information safely, clear loaded modules, and securely gather API keys.

def display_file_if_possible(path, title=None):
   path = Path(path) if path else None
   if not path or not path.exists():
       print(f"Missing file: {path}")
       return
   attempt:
       from IPython.show import show, Image as IPImage, SVG, Markdown
       if title:
           show(Markdown(f"### {title}"))
       suffix = path.suffix.decrease()
       if suffix == ".png":
           show(IPImage(filename=str(path)))
       elif suffix == ".svg":
           show(SVG(filename=str(path)))
       elif suffix in [".json", ".md", ".txt", ".drawio"]:
           print(safe_read(path, max_chars=5000))
       else:
           print(path)
   besides Exception as exc:
       print(f"Could not show {path}: {exc}")
def make_output_gallery(output_dir):
   output_dir = Path(output_dir)
   gallery_path = output_dir / "gallery.html"
   blocks = []
   for p in sorted(output_dir.rglob("*.png")):
       rel = p.relative_to(output_dir)
       blocks.append(f"""
       <div class="card">
         <h3>{rel}</h3>
         <img src="{rel}" />
       </div>
       """)
   for p in sorted(output_dir.rglob("*.svg")):
       rel = p.relative_to(output_dir)
       svg_text = p.read_text(encoding="utf-8", errors="ignore")
       blocks.append(f"""
       <div class="card">
         <h3>{rel}</h3>
         <div class="svgbox">{svg_text}</div>
       </div>
       """)
   for p in sorted(output_dir.rglob("*.drawio")):
       rel = p.relative_to(output_dir)
       code = p.read_text(encoding="utf-8", errors="ignore")[:4000]
       blocks.append(f"""
       <div class="card">
         <h3>{rel}</h3>
         <p>Editable draw.io mxGraph XML file.</p>
         <pre>{code}</pre>
       </div>
       """)
   for p in sorted(output_dir.rglob("generation_report.json")):
       rel = p.relative_to(output_dir)
       attempt:
           report_text = json.dumps(json.masses(p.read_text(encoding="utf-8")), indent=2)[:7000]
       besides Exception:
           report_text = p.read_text(encoding="utf-8", errors="ignore")[:7000]
       blocks.append(f"""
       <div class="card">
         <h3>{rel}</h3>
         <pre>{report_text}</pre>
       </div>
       """)
   html = f"""
   <!doctype html>
   <html>
   <head>
     <meta charset="utf-8">
     <title>AutoFigure Colab Gallery</title>
     <model>
       physique {{
         font-family: Arial, sans-serif;
         margin: 24px;
         background: #f7f7f7;
       }}
       h1 {{
         margin-bottom: 8px;
       }}
       .card {{
         background: white;
         padding: 18px;
         margin: 18px 0;
         border-radius: 14px;
         box-shadow: 0 2px 16px rgba(0,0,0,0.08);
       }}
       img {{
         max-width: 100%;
         border: 1px stable #ddd;
         border-radius: 10px;
       }}
       .svgbox {{
         border: 1px stable #ddd;
         border-radius: 10px;
         padding: 8px;
         overflow: auto;
       }}
       pre {{
         white-space: pre-wrap;
         word-break: break-word;
         max-height: 520px;
         overflow: auto;
         background: #fafafa;
         padding: 12px;
         border-radius: 10px;
       }}
     </model>
   </head>
   <physique>
     <h1>AutoFigure Colab Gallery</h1>
     {''.be part of(blocks)}
   </physique>
   </html>
   """
   gallery_path.write_text(html, encoding="utf-8")
   return gallery_path
def summarize_generation_result(end result, label):
   print("n" + "-" * 100)
   print(label)
   print("-" * 100)
   print(f"Success: {end result.success}")
   print(f"Final rating: {end result.final_score}")
   print(f"Iterations used: {end result.iterations_used}")
   print(f"SVG path: {end result.svg_path}")
   print(f"mxGraph path: {end result.mxgraph_path}")
   print(f"Preview path: {end result.preview_path}")
   print(f"Enhanced path: {end result.enhanced_path}")
   print(f"Enhanced paths: {end result.enhanced_paths}")
   print(f"Error: {end result.error}")
   if end result.logs:
       print("nRecent logs:")
       for log in end result.logs[-20:]:
           print(f"- {log}")
   display_file_if_possible(end result.preview_path, f"{label}: PNG Preview")
   if end result.svg_path:
       display_file_if_possible(end result.svg_path, f"{label}: SVG")
   if end result.mxgraph_path:
       display_file_if_possible(end result.mxgraph_path, f"{label}: mxGraph XML")
   report_candidates = []
   for candidate in [result.svg_path, result.mxgraph_path, result.preview_path]:
       if candidate:
           report_candidates.append(Path(candidate).dad or mum / "generation_report.json")
   for report_path in report_candidates:
       if report_path.exists():
           print("nGeneration report preview:")
           print(safe_read(report_path, max_chars=6000))
           attempt:
               import pandas as pd
               from IPython.show import show
               report = json.masses(report_path.read_text(encoding="utf-8"))
               rows = []
               for row in report.get("iteration_history", []):
                   rows.append({
                       "iteration": row.get("iteration"),
                       "quality_score": row.get("quality_score"),
                       "enchancment": row.get("enchancment"),
                       "has_critique": row.get("critique") is just not None,
                   })
               if rows:
                   show(pd.DataFrame(rows))
           besides Exception as exc:
               print(f"Could not tabulate report: {exc}")
           break

We outline utility capabilities that assist us show generated information straight inside Colab, together with PNG, SVG, JSON, Markdown, textual content, and draw.io outputs. We additionally construct an HTML gallery generator so that every one AutoFigure outputs will be reviewed on a single, organized web page. We then add a result-summary operate that prints era metadata, shows previews, and reveals the iteration report in a readable format.

heading("1. Installing AutoFigure and Colab dependencies")
OUTPUT_ROOT.mkdir(mother and father=True, exist_ok=True)
run("apt-get replace -qq", quiet=True)
run(
   "apt-get set up -y -qq "
   "libcairo2 libpango-1.0-0 libpangocairo-1.0-0 "
   "libgdk-pixbuf-2.0-0 libffi-dev shared-mime-info",
   quiet=True,
)
clear_loaded_modules(["PIL", "autofigure"])
run(f"{sys.executable} -m pip set up -q -U pip 'setuptools<82' wheel jedi", quiet=True)
run(
   f"{sys.executable} -m pip set up -q --force-reinstall --no-cache-dir "
   f"'Pillow==11.3.0'",
   quiet=True,
)
if REPO_DIR.exists():
   print(f"Repository already exists at {REPO_DIR}. Pulling newest most important department.")
   run("git fetch origin most important", cwd=REPO_DIR, quiet=True)
   run("git checkout most important", cwd=REPO_DIR, quiet=True)
   run("git pull --ff-only origin most important", cwd=REPO_DIR, verify=False, quiet=True)
else:
   run(f"git clone {REPO_URL} {REPO_DIR}", quiet=True)
run(
   f"{sys.executable} -m pip set up -q -e '.[pdf,web]' "
   f"reportlab pandas 'Pillow==11.3.0'",
   cwd=REPO_DIR,
   quiet=True,
)
run(
   f"{sys.executable} -m pip set up -q --force-reinstall --no-cache-dir "
   f"'Pillow==11.3.0'",
   quiet=True,
)
clear_loaded_modules(["PIL", "autofigure"])
attempt:
   from PIL import Image, ImageDraw, ImageFont
   print(f"Pillow imported efficiently. Version: {Image.__version__}")
besides Exception as exc:
   print("Pillow import nonetheless failed after reinstall.")
   print("Run Runtime -> Restart runtime, then rerun this full cell.")
   increase exc
if RUN_MXGRAPH_DEMO:
   run(f"{sys.executable} -m playwright set up chromium", quiet=True)
sys.path.insert(0, str(REPO_DIR))
heading("2. Importing AutoFigure SDK")
from autofigure import AutoFigureAgent, Config
from autofigure.generator import (
   validate_code_syntax,
   code_to_png,
   get_initial_prompt_template,
)
from autofigure.extractor import MethodologyExtractor
print("AutoFigure imported efficiently.")
print(f"Repository listing: {REPO_DIR}")
print(f"Output root: {OUTPUT_ROOT}")
heading("3. Offline SVG preflight: validation and rendering")
preflight_dir = OUTPUT_ROOT / "00_offline_preflight"
preflight_dir.mkdir(mother and father=True, exist_ok=True)
sample_svg = """
<svg width="1333" top="750" viewBox="0 0 1333 750" xmlns="http://www.w3.org/2000/svg">
 <rect x="0" y="0" width="1333" top="750" fill="#ffffff"/>
 <textual content x="666" y="70" text-anchor="center" font-family="Arial" font-size="36" font-weight="700" fill="#111111">
   AutoFigure Offline Rendering Check
 </textual content>
 <rect x="120" y="220" width="250" top="140" rx="18" fill="#f3f3f3" stroke="#111111" stroke-width="3"/>
 <textual content x="245" y="285" text-anchor="center" font-family="Arial" font-size="24" fill="#111111">Text Prompt</textual content>
 <textual content x="245" y="325" text-anchor="center" font-family="Arial" font-size="17" fill="#444444">methodology description</textual content>
 <line x1="390" y1="290" x2="565" y2="290" stroke="#111111" stroke-width="4" marker-end="url(#arrow)"/>
 <rect x="585" y="220" width="250" top="140" rx="18" fill="#f3f3f3" stroke="#111111" stroke-width="3"/>
 <textual content x="710" y="285" text-anchor="center" font-family="Arial" font-size="24" fill="#111111">AutoFigure</textual content>
 <textual content x="710" y="325" text-anchor="center" font-family="Arial" font-size="17" fill="#444444">generate → consider → refine</textual content>
 <line x1="855" y1="290" x2="1030" y2="290" stroke="#111111" stroke-width="4" marker-end="url(#arrow)"/>
 <rect x="1050" y="220" width="250" top="140" rx="18" fill="#f3f3f3" stroke="#111111" stroke-width="3"/>
 <textual content x="1175" y="285" text-anchor="center" font-family="Arial" font-size="24" fill="#111111">Figure</textual content>
 <textual content x="1175" y="325" text-anchor="center" font-family="Arial" font-size="17" fill="#444444">SVG + PNG output</textual content>
 <defs>
   <marker id="arrow" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto">
     <path d="M2,2 L10,6 L2,10 Z" fill="#111111"/>
   </marker>
 </defs>
</svg>
""".strip()
is_valid, validation_message = validate_code_syntax(sample_svg, "svg")
print(f"SVG syntax legitimate: {is_valid}")
print(f"Validation message: {validation_message}")
sample_svg_path = preflight_dir / "offline_preflight.svg"
sample_png_path = preflight_dir / "offline_preflight.png"
sample_svg_path.write_text(sample_svg, encoding="utf-8")
render_ok, processed_svg = code_to_png(
   sample_svg,
   str(sample_png_path),
   attempt_repair=False,
   output_format="svg",
)
print(f"Rendered PNG: {render_ok} -> {sample_png_path}")
display_file_if_possible(sample_png_path, "Offline preflight PNG")

We set up the required system packages, resolve Pillow compatibility points, clone the AutoFigure repository, and set up the SDK alongside with its PDF and net dependencies. We then import AutoFigure’s most important lessons and generator utilities after confirming that the setting is prepared. We additionally run offline SVG validation and PNG rendering checks to make sure the rendering pipeline works earlier than making any API-based era calls.

heading("4. Creating a customized reference determine")
reference_dir = OUTPUT_ROOT / "01_custom_references"
reference_dir.mkdir(mother and father=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)
attempt:
   title_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 36)
   box_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 24)
   small_font = ImageFont.truetype("DejaVuSans.ttf", 18)
besides Exception:
   title_font = None
   box_font = None
   small_font = None
draw.textual content(
   (W // 2, 55),
   "Reference Layout: Modular Scientific Pipeline",
   anchor="mm",
   fill="black",
   font=title_font,
)
containers = [
   (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"),
]
for i, (x, y, bw, bh, title, subtitle) in enumerate(containers):
   draw.rounded_rectangle(
       [x, y, x + bw, y + bh],
       radius=22,
       fill=(245, 245, 245),
       define=(20, 20, 20),
       width=3,
   )
   draw.textual content(
       (x + bw / 2, y + 45),
       title,
       anchor="mm",
       fill="black",
       font=box_font,
   )
   draw.textual content(
       (x + bw / 2, y + 82),
       subtitle,
       anchor="mm",
       fill=(70, 70, 70),
       font=small_font,
   )
   if i < len(containers) - 1:
       ax = x + bw + 20
       ay = y + bh / 2
       bx = containers[i + 1][0] - 20
       by = ay
       draw.line([ax, ay, bx, by], fill="black", width=5)
       draw.polygon(
           [(bx, by), (bx - 18, by - 10), (bx - 18, by + 10)],
           fill="black",
       )
draw.rounded_rectangle(
   [180, 500, 1150, 585],
   radius=24,
   fill=(252, 252, 252),
   define=(80, 80, 80),
   width=2,
)
draw.textual content(
   (665, 542),
   "Design cue: aligned modules, sparse labels, sturdy circulate route, clear educational styling",
   anchor="mm",
   fill=(40, 40, 40),
   font=small_font,
)
img.save(reference_path)
print(f"Custom reference saved: {reference_path}")
display_file_if_possible(reference_path, "Custom reference determine")
heading("5. Configuring API-backed AutoFigure")
API_KEY = collect_api_key(PROVIDER)
if not API_KEY:
   print("No API key offered. Cloud era sections can be skipped.")
else:
   print(f"Provider: {PROVIDER}")
   print(f"Generation mannequin: {GENERATION_MODEL}")
   print("API key obtained. The key is just not printed.")
config = None
agent = None
if API_KEY:
   config = Config(
       generation_api_key=API_KEY,
       generation_provider=PROVIDER,
       generation_model=GENERATION_MODEL,
       methodology_api_key=API_KEY,
       methodology_provider=PROVIDER,
       methodology_model=GENERATION_MODEL,
       enhancement_api_key=API_KEY if RUN_IMAGE_ENHANCEMENT else None,
       enhancement_provider=PROVIDER,
       enhancement_model=os.environ.get(
           "AUTOFIGURE_ENHANCEMENT_MODEL",
           "google/gemini-3.1-flash-image-preview"
           if PROVIDER == "openrouter"
           else "gemini-3.1-flash-image-preview",
       ),
       max_iterations=MAX_ITERATIONS,
       quality_threshold=QUALITY_THRESHOLD,
       output_dir=str(OUTPUT_ROOT / "02_text_to_figure"),
       custom_references=[str(reference_path)],
       art_style=ART_STYLE,
   )
   validation_errors = config.validate()
   print(f"Config validation errors: {validation_errors if validation_errors else 'none'}")
   print(f"References discovered by config: {len(config.get_references())}")
   agent = AutoFigureAgent(config)
heading("6. Prompt template preview")
prompt_preview = get_initial_prompt_template(
   subject="paper",
   content material=FIGURE_DESCRIPTION[:2500],
   output_format="svg",
)
print(prompt_preview[:2500])
print("n... immediate preview truncated ...")
if API_KEY and RUN_TEXT_TO_FIGURE:
   heading("7. Running text-to-figure era")
   text_output_dir = OUTPUT_ROOT / "02_text_to_figure"
   text_output_dir.mkdir(mother and father=True, exist_ok=True)
   text_result = agent.generate(
       description=FIGURE_DESCRIPTION,
       max_iterations=MAX_ITERATIONS,
       quality_threshold=QUALITY_THRESHOLD,
       output_format=TEXT_OUTPUT_FORMAT,
       enable_enhancement=RUN_IMAGE_ENHANCEMENT,
       art_style=ART_STYLE,
       enhancement_input_type="code2prompt",
       enhancement_count=1,
       custom_references=[str(reference_path)],
       output_dir=str(text_output_dir),
       subject="paper",
   )
   summarize_generation_result(text_result, "Text-to-Figure Result")
else:
   print("Skipping text-to-figure era.")

We create a customized reference picture that reveals the type of clear modular scientific structure we would like AutoFigure to observe. We then configure AutoFigure with the chosen supplier, mannequin, API key, output listing, reference picture, iteration settings, and visible model. Finally, we preview the inner immediate template and run the primary text-to-figure era workflow to provide a scientific determine from our detailed system description.

heading("8. Paper methodology extraction dry verify")
paper_dir = OUTPUT_ROOT / "03_paper_to_figure"
paper_dir.mkdir(mother and father=True, exist_ok=True)
paper_md_path = paper_dir / "mini_paper.md"
paper_md_path.write_text(MINI_PAPER_MARKDOWN, encoding="utf-8")
if API_KEY:
   if RUN_PAPER_TO_FIGURE:
       extractor = MethodologyExtractor(config)
       extracted = extractor.extract_from_file(str(paper_md_path))
       print("nExtracted methodology preview:")
       print((extracted or "")[:2500])
   else:
       print(f"Created demo paper markdown at: {paper_md_path}")
       print("Set RUN_PAPER_TO_FIGURE = True to run LLM methodology extraction and determine era.")
else:
   print(f"Created demo paper markdown at: {paper_md_path}")
   print("No API key obtainable, so LLM methodology extraction is skipped.")
if API_KEY and RUN_PAPER_TO_FIGURE:
   heading("9. Running paper-to-figure era")
   paper_result = agent.generate_from_paper(
       paper_path=str(paper_md_path),
       max_iterations=MAX_ITERATIONS,
       output_format="svg",
       enable_enhancement=RUN_IMAGE_ENHANCEMENT,
       art_style=ART_STYLE,
       enhancement_input_type="code2prompt",
       enhancement_count=1,
       custom_references=[str(reference_path)],
       output_dir=str(paper_dir),
   )
   summarize_generation_result(paper_result, "Paper-to-Figure Result")
heading("10. Creating a tiny PDF and testing PDF textual content studying")
pdf_path = paper_dir / "mini_paper.pdf"
attempt:
   from reportlab.lib.pagesizes import letter
   from reportlab.pdfgen import canvas
   c = canvas.Canvas(str(pdf_path), pagesize=letter)
   width, top = letter
   y = top - 50
   for line in MINI_PAPER_MARKDOWN.splitlines():
       line = line.strip()
       if not line:
           y -= 12
           proceed
       for wrapped in textwrap.wrap(line, width=95):
           c.drawString(50, y, wrapped)
           y -= 14
           if y < 60:
               c.presentPage()
               y = top - 50
   c.save()
   print(f"Created demo PDF: {pdf_path}")
   if API_KEY:
       pdf_text = MethodologyExtractor(config)._read_pdf(pdf_path)
       print("PDF textual content extraction preview:")
       print((pdf_text or "")[:1500])
   else:
       print("PDF created. LLM-based paper-to-figure era nonetheless requires an API key.")
besides Exception as exc:
   print(f"PDF creation or learn check failed: {exc}")
if API_KEY and RUN_MXGRAPH_DEMO:
   heading("11. Running editable mxGraph XML era")
   mxgraph_dir = OUTPUT_ROOT / "04_mxgraph_drawio"
   mxgraph_dir.mkdir(mother and father=True, exist_ok=True)
   mx_result = agent.generate(
       description=FIGURE_DESCRIPTION,
       max_iterations=MAX_ITERATIONS,
       quality_threshold=QUALITY_THRESHOLD,
       output_format=MXGRAPH_OUTPUT_FORMAT,
       enable_enhancement=False,
       custom_references=[str(reference_path)],
       output_dir=str(mxgraph_dir),
       subject="paper",
   )
   summarize_generation_result(mx_result, "mxGraph / draw.io Result")
else:
   heading("11. mxGraph XML era skipped")
   print("Set RUN_MXGRAPH_DEMO = True to generate editable draw.io mxGraph XML.")
   print("This path installs Chromium via Playwright and could also be slower than SVG era.")
heading("12. Output stock and export")
all_files = []
for path in sorted(OUTPUT_ROOT.rglob("*")):
   if path.is_file():
       all_files.append(path)
print(f"Total information underneath {OUTPUT_ROOT}: {len(all_files)}")
for path in all_files:
   rel = path.relative_to(OUTPUT_ROOT)
   size_kb = path.stat().st_size / 1024
   print(f"{rel}  ({size_kb:.1f} KB)")
gallery_path = make_output_gallery(OUTPUT_ROOT)
print(f"nGallery HTML: {gallery_path}")
zip_base = "/content material/autofigure_colab_outputs"
zip_path = shutil.make_archive(zip_base, "zip", root_dir=str(OUTPUT_ROOT))
print(f"Zip archive: {zip_path}")
attempt:
   from IPython.show import show, HTML
   show(
       HTML(
           f"""
           <h3>AutoFigure tutorial full</h3>
           <p><b>Output root:</b> {OUTPUT_ROOT}</p>
           <p><b>Gallery:</b> {gallery_path}</p>
           <p><b>Zip:</b> {zip_path}</p>
           """
       )
   )
besides Exception:
   cross
print("nDone.")
print("If the mannequin is unavailable or entry is denied, change PROVIDER and GENERATION_MODEL close to the highest of the cell.")

We create a small paper-style Markdown file and optionally use AutoFigure’s methodology extractor to generate a determine from paper content material. We additionally create a easy PDF model of the paper and check whether or not the PDF textual content extraction pipeline works accurately. We end by optionally working the mxGraph draw.io workflow, itemizing all generated information, constructing the HTML gallery, and exporting the whole output folder as a zipper archive.

In conclusion, we accomplished this tutorial by constructing a full AutoFigure workflow that strikes from setting setup to determine era, validation, previewing, and export. We noticed how AutoFigure helps us remodel complicated analysis or system descriptions into structured scientific visuals whereas nonetheless giving us management over references, model, output format, iterations, and non-obligatory paper-based extraction. By the top, we’ve a Colab-ready pipeline that may generate SVG figures and put together editable drawings. io-style outputs when wanted, check PDF extraction, and package deal all generated property for later use.


Check out the FULL CODES here. Also, be at liberty to observe us on Twitter and don’t overlook to affix our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to companion with us for selling your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar and so forth.? Connect with us

The publish Building Agentic Document Intelligence Pipelines: Creating Scientific Figures with AutoFigure appeared first on MarkTechPost.

Similar Posts