How dwzhu-pku/paperbanana works
1. What this repo is
PaperBanana is an academic illustration generation system for two task families: diagrams and plots. Its core architecture is a multi-agent pipeline that turns paper text and captions into generated figures, optionally using reference examples from a benchmark dataset.
2. Main entrypoints
The repository has three primary execution paths:
- main.py: command-line batch execution and evaluation
- app.py: a Gradio-based interactive app
- demo.py: a Streamlit demo for candidate generation and image refinement
Additional Streamlit tools live under visualize/ for inspecting pipeline evolution and evaluation results.
3. Core orchestration layer
The real system behavior is in agents/, which encodes the pipeline as modular roles:
- Retriever Agent: selects relevant reference figures
- Planner Agent: expands source text into a structured figure plan
- Stylist Agent: rewrites the plan to match publication-style conventions
- Visualizer Agent: calls image generation models to render candidates
- Critic Agent: evaluates outputs and drives iterative refinement
- Vanilla Agent: direct generation baseline
- Polish Agent: post-processing/refinement path
4. Pipeline structure and control flow
The architecture is centered on a reference-driven generation loop:
- Input: method text, caption, task type, and optional retrieval examples
- Optional retrieval: choose similar references from the benchmark
- Planning: convert content into a figure-specification
- Styling: adapt the spec to academic design norms
- Visual synthesis: generate one or more candidate images
- Critique/refinement: compare candidate against goals and iterate
The README exposes several modes, from vanilla to full pipeline with critic rounds, which suggests the pipeline is designed as composable stages rather than a monolith.
5. Data and knowledge sources
The system depends on a benchmark dataset stored under data/PaperBananaBench/ when available. This dataset provides:
- task instances for diagram and plot generation
- reference images and metadata for retrieval
- evaluation targets / held-out splits
The repo is designed to degrade gracefully without the dataset by skipping the few-shot retrieval path.
6. Configuration and model routing
Configuration is externalized in configs/model_config.yaml created from the template. This file controls:
- the main multimodal model used for reasoning/planning
- the image generation model
- API keys for providers such as Google Gemini or OpenRouter
This makes model selection a first-class architectural boundary: reasoning and image synthesis can be swapped independently.
7. Prompting and style guidance
The prompts/ and style_guides/ directories hold the reusable textual assets that shape agent behavior:
- task-specific evaluation prompts for diagrams and plots
- automatically synthesized style guides
- category/style reference materials
These are not code paths but are part of the control surface of the system, especially for the Stylist and Critic stages.
8. Utility layer
Shared functionality is concentrated in utils/:
- configuration loading
- generation helpers and async/concurrency support
- image manipulation and export
- dataset/paper visualization preprocessing
- evaluation toolkits
This layer acts as the glue between agent logic, model APIs, file outputs, and evaluation.
9. Evaluation and analysis
The repo includes a built-in evaluation workflow, mainly for benchmarked diagram/plot outputs. Evidence of this appears in:
- utils/eval_toolkits.py
- **prompts/*_eval_prompts.py**
- visualize/show_referenced_eval.py
The architecture therefore includes a closed loop: generate figures, score them against references/targets, and inspect results visually.
10. Artifacts and outputs
Generated images, intermediate candidates, timelines, and batch exports appear to be stored under results/ at runtime. The demo mode emphasizes producing multiple candidates and preserving evolution artifacts, which suggests the pipeline is not only generative but also traceable for inspection.
11. User interface boundary
The repo separates the model pipeline from user interaction:
- Gradio app for direct generation and API-key-driven usage
- Streamlit demo for candidate grids, refinement, and downloads
- Visualization apps for post hoc analysis
This UI layer sits on top of the same agent pipeline and does not own generation logic.
12. Deployment and packaging
The repo is packaged for local Python execution with requirements.txt, a Dockerfile, shell scripts in scripts/, and static frontend assets in static/ and assets/. It is also published as a ClawHub skill (skill/), which indicates an additional integration boundary for agent platforms.
13. Overall architectural picture
The system is best understood as:
input text + optional retrieved references → multi-agent text planning and styling → image synthesis → critique/refinement → downloadable figure outputs, with separate presentation layers for interactive use and separate evaluation/visualization tools for benchmarking and debugging.
Main entry points: visualizer_agent.py Visualizer · critic_agent.py Critic · main.py main.py · base_agent.py Base Agent
Components 24
Entrypoints
Command-line, app, and demo surfaces
Pipeline Core
Multi-agent generation and refinement stages
- Retriever · Selects relevant benchmark examples
agents/retriever_agent.py - Planner · Expands source text into a structured figure plan
agents/planner_agent.py - Stylist · Adapts plans to publication-style conventions
agents/stylist_agent.py - Visualizer · Calls image generation models to render candidates
agents/visualizer_agent.py - Critic · Evaluates outputs and drives iterative refinement
agents/critic_agent.py - Vanilla · Direct generation baseline path
agents/vanilla_agent.py - Polish · Post-processing and refinement path
agents/polish_agent.py - Base Agent · Shared agent abstraction and common behavior
agents/base_agent.py
Support Assets
Prompts, style guides, config, and utilities
- Model Config · Externalized model and provider configuration
configs/model_config.template.yaml - Config Utils · Loads and resolves configuration for runtime use
utils/config.py - Generation Utils · Async orchestration and generation helper routines
utils/generation_utils.py - Image Utils · Image manipulation, export, and formatting helpers
utils/image_utils.py - Eval Toolkits · Benchmark evaluation helpers and metrics
utils/eval_toolkits.py - Diagram Prompts · Prompt templates for diagram evaluation
prompts/diagram_eval_prompts.py - Plot Prompts · Prompt templates for plot evaluation
prompts/plot_eval_prompts.py - Style Guides · Reusable style guidance for academic figure conventions
style_guides/neurips2025_diagram_style_guide.md
Ops and Analysis
Packaging, scripts, visualization, and runtime artifacts
- PaperBananaBench · Reference figures, metadata, and task instances
- Results · Generated candidates, intermediate artifacts, and exports
- Eval Viewer · Visual inspection of referenced evaluation results
visualize/show_referenced_eval.py - Pipeline Viewer · Visualization of pipeline evolution and traces
visualize/show_pipeline_evolution.py - Skill Runtime · Agent-platform integration entrypoint
skill/run.py
Connections 27
- main.py → Retriever: batch run · Executes the full generation pipeline for benchmark batches
- main.py → Planner: plan · Creates structured figure specifications
- main.py → Visualizer: render · Generates candidate figures
- main.py → Critic: evaluate · Scores outputs and coordinates refinement
- app.py → Planner: interactive flow · Routes user input into the same planning stages
- demo.py → Visualizer: candidate gen · Produces candidate images for inspection
- demo.py → Polish: refine · Supports post-processing and refinement
- Retriever → PaperBananaBench: lookup · Finds similar references from the benchmark
- Planner → Stylist: handoff · Refined plan is adapted to publication norms
- Stylist → Visualizer: spec to image · Converts styled plans into generated candidates
- Visualizer → Critic: candidates · Sends rendered figures for critique
- Critic → Polish: revise · Feeds refinement decisions back into post-processing
- Vanilla → Visualizer: direct path · Bypasses multi-stage planning for baseline generation
- Base Agent → Retriever: shared base · Common agent abstraction used by specialized roles
- Base Agent → Planner: shared base · Common agent abstraction used by specialized roles
- Base Agent → Stylist: shared base · Common agent abstraction used by specialized roles
- Base Agent → Visualizer: shared base · Common agent abstraction used by specialized roles
- Config Utils → Model Config: loads · Resolves model and provider settings at runtime
- Generation Utils → Visualizer: orchestrates · Supports concurrent generation and call sequencing
- Image Utils → Results: writes · Stores exported images and derived artifacts
- Eval Toolkits → Critic: scores · Provides evaluation logic for comparison against targets
- Diagram Prompts → Critic: guides · Shapes diagram-specific evaluation behavior
- Plot Prompts → Critic: guides · Shapes plot-specific evaluation behavior
- Style Guides → Stylist: guides · Provides reusable academic style conventions
- Eval Viewer → Results: inspect · Reads stored evaluations for analysis
- Pipeline Viewer → Results: trace · Shows pipeline evolution and intermediate outputs
- Skill Runtime → main.py: entry · Publishes the pipeline as a skill runtime