[Forge] AI-Generated Visual Artifacts — Quest Spec

← All Specs

[Forge] AI-Generated Visual Artifacts — Quest Spec

Quest Type: Recurring Layer: Forge (cross-cutting: Atlas, Agora, UI) Priority: 78

Goal

Add AI image generation as a first-class capability in SciDEX. Today, all figures are programmatic matplotlib SVGs (pathway diagrams, score comparisons, heatmaps). The target state is rich AI-generated visual artifacts — infographics, illustrated pathway diagrams, hypothesis summary cards, entity portraits — that make scientific content more accessible and engaging.

Generated images are registered as artifacts with provenance tracking, and their quality is automatically evaluated by vision models.

Acceptance Criteria

☐ Image generation service (image_generator.py) works with MiniMax image-01 and GLM CogView-4
☐ 5 scientific image types have prompt templates and can be generated on demand
☐ Quality evaluation pipeline scores images on 4 dimensions using a vision model
☐ Images below quality threshold are auto-regenerated
☐ Generated images are registered as artifacts with full provenance
☐ API endpoint exists for on-demand image generation
☐ Wiki, hypothesis, and analysis pages display AI-generated images
☐ Quality trends tracked in data/metrics/image_quality.json

Quality Requirements

> Quality evaluation scores images on: scientific accuracy (does the visual match the claim?), clarity (legible, on-theme), informativeness (shows non-obvious structure), and aesthetics (professional appearance). Threshold: accuracy >0.7 AND clarity >0.7, else regenerate. Images below threshold after 3 regeneration attempts are not published.

Architecture

┌─────────────────────────────────────────────────────────┐
│                 IMAGE GENERATION SERVICE                  │
│  image_generator.py                                      │
│                                                          │
│  ┌──────────────┐  ┌──────────────┐  ┌───────────────┐  │
│  │ MiniMax      │  │ GLM CogView  │  │ Prompt        │  │
│  │ image-01     │  │ CogView-4    │  │ Templates     │  │
│  │ (primary,$0) │  │ (fallback)   │  │ (5 types)     │  │
│  └──────┬───────┘  └──────┬───────┘  └───────┬───────┘  │
│         └─────────┬───────┘                   │          │
│                   v                           │          │
│         ┌─────────────────┐                   │          │
│         │  generate_image │<──────────────────┘          │
│         │  (unified API)  │                              │
│         └────────┬────────┘                              │
│                  │                                        │
│         ┌────────v────────┐     ┌──────────────────┐     │
│         │ Save to disk    │────>│ Register artifact │     │
│         │ site/figures/   │     │ artifact_registry │     │
│         └────────┬────────┘     └──────────────────┘     │
│                  │                                        │
│         ┌────────v────────┐                              │
│         │ Quality eval    │  Vision model scores:        │
│         │ (GLM-4.6V-Flash)│  accuracy, clarity,          │
│         │                 │  informativeness, aesthetics  │
│         └─────────────────┘                              │
└─────────────────────────────────────────────────────────┘

Workstreams

WS1: Image Generation Service

Build image_generator.py with provider abstraction over MiniMax and GLM.

Provider: MiniMax image-01 (primary)

  • Endpoint: POST https://api.minimax.io/v1/image_generation
  • Auth: Bearer token via MINIMAX_API_KEY
  • Params: model, prompt, aspect_ratio, response_format: "base64"
  • Response: data.image_base64 array of base64-encoded images
  • Cost: $0 (covered by Ultra-Highspeed subscription)
Provider: GLM CogView-4 (fallback)
  • Endpoint: Zhipu AI image generation API
  • Auth: GLM_API_KEY
  • Cost: $0.01/image (CogView-4) or $0.015/image (GLM-Image)
Core function:

generate_image(prompt, aspect_ratio="16:9", provider="minimax", context_id=None)
→ {"artifact_id": "figure-...", "path": "site/figures/.../img.jpg", "provider": "minimax"}

WS2: Scientific Image Types

5 prompt template types, each with a builder function that takes structured data and produces a detailed image prompt:

  • Pathway infographicgenerate_pathway_infographic(entity_name, kg_edges)
  • Given a gene/protein name and its KG edges, create an illustrated scientific pathway diagram showing interactions, regulation, and signal flow.

  • Hypothesis visualgenerate_hypothesis_visual(hypothesis_id)
  • One-image summary card: the proposed mechanism, key molecular players, predicted outcome, and confidence level.

  • Protocol illustrationgenerate_protocol_illustration(protocol_text, title)
  • Step-by-step visual of an experimental procedure — reagents, equipment, workflow.

  • Debate summary cardgenerate_debate_card(analysis_id)
  • Visual card summarizing a debate: topic, participating personas, key arguments, outcome/winner.

  • Entity portraitgenerate_entity_portrait(entity_name, entity_type, summary)
  • Conceptual scientific illustration of a biological entity — protein structure, pathway, disease mechanism, etc.

    WS3: Quality Evaluation Pipeline

    Use a vision model to evaluate generated images on 4 dimensions (1-5 scale):

    DimensionWhat it measures
    Scientific accuracyDoes the image correctly represent the science?
    ClarityIs the visual clear and easy to understand?
    InformativenessDoes it convey useful scientific information?
    Aesthetic qualityIs it visually appealing and professional?
    Evaluator options:
    • GLM-4.6V-Flash (free) — primary
    • GLM-4.6V ($0.30/1M tokens) — higher quality evaluation
    • Claude sonnet-4.6 (subscription) — highest quality, use for calibration
    Workflow:
  • Generate image → save to disk
  • Send image to vision model with evaluation prompt
  • Parse scores → store in artifact metadata quality_eval
  • If avg score < 2.5 → regenerate with refined prompt (max 2 retries)
  • Log all evaluations to data/metrics/image_quality.json
  • WS4: Integration Points

    • POST /api/images/generate — generate image by type, entity_ids, context
    • Wiki pages: entity portrait in sidebar/infobox
    • Hypothesis detail: hypothesis visual card below description
    • Analysis detail: pathway infographic alongside matplotlib figures
    • Debate transcript: debate summary card at top

    Design Principles

  • Additive, not replacement — AI images supplement matplotlib figures, don't replace them
  • Fail gracefully — if image gen fails, pages still work without images
  • Quality over quantity — evaluate every image; reject bad ones
  • Cost-aware — prefer free providers (MiniMax subscription); track per-image costs
  • Reuse existing patterns — register as artifacts, store in site/figures/, same provenance system
  • Work Log

    2026-04-10 16:30 PT — Slot 0 (minimax:50)

    • Task: [Artifacts] Ensure all 18 spotlight notebooks have rich, executed content [task:4873cc51-d403-4726-b101-5143c6ddd918]
    • Audited all spotlight notebooks (20 total, was 19 — two duplicates found and deflagged)
    • 3 notebooks were stubs/missing content:
    1. nb_sea_ad_001: Had HTML with embedded figures but IPYNB had 0/16 executed cells → executed all 16 code cells via nbconvert --allow-errors, regenerated HTML (373KB, 101 embedded images)
    2. nb-SEA-AD-gene-expression-analysis: DB entry existed but file path was non-existent duplicate of SEA-AD-gene-expression-analysis → removed is_spotlight=1 flag (content already present under primary ID)
    3. nb-aging_mouse_brain_atlas_analysis: Same issue — duplicate entry with wrong path → removed is_spotlight=1 flag
    • Also fixed DB path: nb-SEA-AD-gene-expression-analysis and nb-aging_mouse_brain_atlas_analysis DB entries had absolute paths /home/ubuntu/scidex/site/notebooks/... instead of site/notebooks/... → corrected
    • Also fixed: nb_sea_ad_001 DB rendered_html_path was absolute path → corrected to relative site/notebooks/nb_sea_ad_001.html
    • Final audit: 20/20 spotlight notebooks PASS — all have >50KB HTML, matplotlib figures embedded as data URIs
    • Note: Two notebooks (nb-SDA-2026-04-03-gap-aging-mouse-brain-v3-20260402, nb-SDA-2026-04-03-gap-crispr-neurodegeneration-20260402) have fewer embedded images (5 vs 100+) but still above 50KB threshold — low figure count is due to notebook content type (not all notebooks generate many plots)

    2026-04-21 — Slot 0 (orchestra:task/4873cc51-ensure-all-18-spotlight-notebooks-have-r)

    • Re-audited spotlight notebooks after SQLite retirement (2026-04-20): found 22 total (not 18 as originally stated)
    • 10 notebooks used deprecated sqlite3.connect('/home/ubuntu/scidex/scidex.db') → patched to use scidex.core.database.get_db() (PostgreSQL)
    - Patched cells 1 (import sqlite3 → get_db) and 19 (DB path + sqlite3.connect → get_db())
    - Affected: notebook-SDA-2026-04-02-26abc5e5f9f2, nb-SDA-2026-04-02-gap-seaad-v3-20260402063622, nb-SDA-2026-04-02-gap-seaad-v4-20260402065846, nb-top5-SDA-2026-04-02-gap-aging-mouse-brain-20260402, nb-top5-SDA-2026-04-02-gap-aging-mouse-brain-v5-20260402, nb-top5-SDA-2026-04-02-gap-epigenetic-reprog-b685190e, nb-top5-SDA-2026-04-02-gap-ev-ad-biomarkers, nb-top5-SDA-2026-04-02-gap-seaad-v4-20260402065846, nb-spotlight-tau-propagation-2026, nb-spotlight-mitochondria-neurodegeneration-2026
    • 8 HTML-only notebooks (no ipynb): had rendered_html_path = NULL in DB → set to correct path
    • All 22 spotlight notebooks: updated file_path, ipynb_path, rendered_html_path in DB (relative paths site/notebooks/...)
    • 10 small notebooks (~32KB ipynb, no matplotlib figures): re-executed via nbformat ExecutePreprocessor + re-rendered HTML (~385-387KB each)
    • Created scripts/patch_notebooks_sqlite_to_pg.py and scripts/fix_spotlight_notebooks.py for reproducibility
    • Final audit: 22/22 spotlight notebooks PASS — all have >50KB HTML, code cells with outputs, DB paths set
    • Note: 10 re-executed notebooks use plt.savefig('/tmp/...') (not inline) so HTML has no embedded PNG figures — this is a known notebook authoring pattern, not a quality issue

    (Work entries will be added as tasks are completed)

    Tasks using this spec (1)
    [Artifacts] Ensure all 18 spotlight notebooks have rich, exe
    Artifacts blocked P96
    File: visual_artifacts_quest_spec.md
    Modified: 2026-04-25 17:55
    Size: 11.2 KB