--- title: IIIF Studio emoji: ๐Ÿ“œ colorFrom: blue colorTo: yellow sdk: docker app_port: 7860 pinned: false --- # IIIF Studio A generic platform for generating AI-augmented scholarly editions from digitized heritage documents โ€” medieval manuscripts, incunabula, cartularies, archives, charters, papyri. Any document type, any era, any language. IIIF Studio ingests images from any [IIIF](https://iiif.io/)-compliant server, analyzes them with multimodal AI (Google Gemini, Mistral), and produces structured scholarly data: diplomatic OCR, layout detection, translations, commentaries, and iconographic analysis โ€” all exportable as ALTO XML, METS, and IIIF Presentation 3.0 manifests. **Images are never stored locally.** The platform streams them from origin servers using the IIIF Image API, storing only the AI-generated metadata (~5 KB per page instead of ~50 MB). --- ## Features - **IIIF-native architecture** โ€” images streamed from origin servers (Gallica, BnF, Bodleian, etc.) with tiled deep zoom via OpenSeadragon - **Multi-provider AI** โ€” Google AI Studio, Vertex AI, Mistral AI. Model selected per corpus, auto-detected from environment - **Profile-driven analysis** โ€” 4 built-in corpus profiles (medieval illuminated, medieval textual, early modern print, modern handwritten), each with tailored prompts and active layers - **Structured output** โ€” layout regions with bounding boxes, diplomatic OCR, translations (FR/EN), scholarly and public commentary, iconographic analysis, uncertainty tracking - **Standards-compliant export** โ€” IIIF Presentation 3.0 manifests (with Image Service for tiled zoom), ALTO XML, METS XML, ZIP bundles - **Human-in-the-loop** โ€” editorial correction interface with versioned history and rollback - **Full-text search** โ€” accent-insensitive search across OCR text, translations, and iconographic tags --- ## Architecture ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ IIIF IMAGE SERVERS โ”‚ โ”‚ Gallica ยท BnF ยท Bodleian ยท Europeana ยท ... โ”‚ โ”‚ (origin โ€” images are never copied) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ info.json โ”‚ /full/!1500,1500/ โ”‚ /full/max/ โ”‚ + tiles โ”‚ 0/default.jpg โ”‚ 0/default.jpg โ”‚ โ”‚ (1500px for AI) โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ FRONTEND (SPA) โ”‚ โ”‚ BACKEND (API) โ”‚ โ”‚ EXPORT GENERATORS โ”‚ โ”‚ React + Vite โ”‚ โ”‚ FastAPI โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ IIIF Manifest 3.0 โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ (with Image Service refs) โ”‚ โ”‚ โ”‚ OpenSeadragon โ”‚ โ”‚ โ”‚ โ”‚ Ingestion โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ IIIF tiled zoom โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ METS XML โ”‚ โ”‚ โ”‚ (info.json โ†’ โ”‚ โ”‚ โ”‚ โ”‚ manifest URL โ”‚ โ”‚ โ”‚ (IIIF URLs, not file paths) โ”‚ โ”‚ โ”‚ deep zoom) โ”‚ โ”‚ โ”‚ โ”‚ โ†’ detect svc โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ†’ store meta โ”‚ โ”‚ โ”‚ ALTO XML โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ (text geometry per page) โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Region overlays โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚ โ”‚ ZIP bundle โ”‚ โ”‚ โ”‚ (bbox from โ”‚ โ”‚ โ”‚ โ”‚ AI Pipeline โ”‚โ”‚ โ”‚ (manifest + METS + ALTO) โ”‚ โ”‚ โ”‚ master.json, โ”‚ โ”‚ โ”‚ โ”‚ โ”‚โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ scaled to โ”‚ โ”‚ โ”‚ โ”‚ fetch 1500pxโ”‚โ”‚ โ”‚ โ”‚ canvas coords) โ”‚ โ”‚ โ”‚ โ”‚ in memory โ”‚โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ–ผ โ”‚โ”‚ โ”‚ AI PROVIDERS โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ send bytes โ”‚โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ โ”‚ โ”‚ โ”‚ Pages โ”‚ โ”‚ โ”‚ โ”‚ to AI โ”‚โ”‚ โ”‚ Google Gemini โ”‚ โ”‚ โ”‚ Home ยท Reader โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Vertex AI โ”‚ โ”‚ โ”‚ Editor ยท Admin โ”‚ โ”‚ โ”‚ โ”‚ โ–ผ โ”‚โ”‚ JSON โ”‚ Mistral AI โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ discard img โ”‚โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ keep JSON โ”‚โ”‚ โ”‚ (auto-detected from โ”‚ โ”‚ โ”‚ REST API โ”‚ โ”‚ โ”‚ scale bbox โ”‚โ”‚ โ”‚ environment vars) โ”‚ โ”‚ โ”‚ /api/v1/* โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚ โ”‚ โ”‚ โ”‚ Response โ”‚โ”‚ โ”‚ โ”‚ โ”‚ Parser โ”‚โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚โ”‚ โ”‚ โ”‚ raw JSON โ”‚โ”‚ โ”‚ โ”‚ โ†’ layout โ”‚โ”‚ โ”‚ โ”‚ โ†’ OCR โ”‚โ”‚ โ”‚ โ”‚ โ†’ regions โ”‚โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚ โ”‚ โ”‚ Master โ”‚โ”‚ โ”‚ โ”‚ Writer โ”‚โ”‚ โ”‚ โ”‚ โ”‚โ”‚ โ”‚ โ”‚ ai_raw.json โ”‚โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ master.json โ”‚โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚ โ”‚ LOCAL STORAGE โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ SQLite (corpus, pages, โ”‚ โ”‚ โ”‚ manuscripts, jobs, models) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โ”‚ โ”‚ data/corpora/{slug}/pages/ โ”‚ โ”‚ {folio}/master.json โ”‚ โ”‚ {folio}/ai_raw.json โ”‚ โ”‚ {folio}/alto.xml โ”‚ โ”‚ โ”‚ โ”‚ ~5 KB per page (JSON only) โ”‚ โ”‚ NO image binaries โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ PIPELINE FLOW (per page): โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ 1.INGEST โ”‚โ”€โ”€โ”€โ–บโ”‚ 2.DETECT โ”‚โ”€โ”€โ”€โ–บโ”‚ 3.FETCH โ”‚โ”€โ”€โ”€โ–บโ”‚ 4.AI โ”‚โ”€โ”€โ”€โ–บโ”‚ 5.PARSE โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ manifest โ”‚ โ”‚ IIIF svc โ”‚ โ”‚ 1500px โ”‚ โ”‚ send โ”‚ โ”‚ layout โ”‚ โ”‚ URL โ”‚ โ”‚ URL + โ”‚ โ”‚ JPEG in โ”‚ โ”‚ image + โ”‚ โ”‚ regions โ”‚ โ”‚ โ”‚ โ”‚ canvas โ”‚ โ”‚ memory โ”‚ โ”‚ prompt โ”‚ โ”‚ OCR โ”‚ โ”‚ โ”‚ โ”‚ dims โ”‚ โ”‚ (discard โ”‚ โ”‚ to โ”‚ โ”‚ bbox โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ after) โ”‚ โ”‚ provider โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ” โ”‚ 8.EXPORT โ”‚โ—„โ”€โ”€โ”€โ”‚ 7.REVIEW โ”‚โ—„โ”€โ”€โ”€โ”‚ 6.WRITE โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ 5b.SCALE โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ IIIF 3.0 โ”‚ โ”‚ human โ”‚ โ”‚ ai_raw + โ”‚ โ”‚ bbox โ”‚ โ”‚ ALTO XML โ”‚ โ”‚ correct โ”‚ โ”‚ master โ”‚ โ”‚ deriv โ†’ โ”‚ โ”‚ METS XML โ”‚ โ”‚ validate โ”‚ โ”‚ .json โ”‚ โ”‚ canvas โ”‚ โ”‚ ZIP โ”‚ โ”‚ version โ”‚ โ”‚ + ALTO โ”‚ โ”‚ coords โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ### Tech stack | Layer | Technology | |-------|-----------| | Backend | Python 3.11+, FastAPI, Uvicorn | | Database | SQLite via SQLAlchemy 2.0 async + aiosqlite | | Validation | Pydantic v2 | | AI providers | Google Gemini (google-genai SDK), Mistral AI | | Image viewer | OpenSeadragon (IIIF tiled zoom) | | Frontend | React 18, TypeScript, Vite, Tailwind CSS, React Router | | Exports | lxml (ALTO/METS XML), IIIF Presentation 3.0 | | Deployment | Docker (HuggingFace Spaces) | --- ## Quick start ### Docker (recommended) ```bash git clone https://github.com/maribakulj/IIIF-Studio.git && cd IIIF-Studio # Configure at least one AI provider key cp .env.example .env # Edit .env and add your API key(s) # Build and run docker compose -f infra/docker-compose.yml up --build # Open http://localhost:7860 ``` ### Local development ```bash # Backend cd backend pip install -e ".[dev]" uvicorn app.main:app --reload --port 7860 # Frontend (separate terminal) cd frontend npm install npm run dev ``` The API is available at `http://localhost:7860/api/v1/`. Interactive Swagger docs at `http://localhost:7860/docs`. --- ## Usage workflow 1. **Create a corpus** โ€” select a profile matching your document type 2. **Ingest pages** โ€” provide a IIIF manifest URL, direct image URLs, or upload files 3. **Select an AI model** โ€” choose a provider and model from the detected options 4. **Run the pipeline** โ€” AI analyzes each page: layout detection, OCR, translation, commentary 5. **Review and correct** โ€” use the Editor to validate, correct OCR, adjust regions 6. **Export** โ€” download IIIF manifest, ALTO XML, METS XML, or a ZIP bundle --- ## Corpus profiles Profiles control which analysis layers are active, which prompt templates are used, and what uncertainty thresholds apply. | Profile | Script | Languages | Key layers | |---------|--------|-----------|------------| | `medieval-illuminated` | Caroline | Latin, French | OCR, translation, iconography, commentary, material notes | | `medieval-textual` | Gothic | Latin, French | OCR, translation, scholarly commentary | | `early-modern-print` | Print | French, Latin | OCR, summary | | `modern-handwritten` | Cursive | French | OCR, summary | Custom profiles can be added as JSON files in the `profiles/` directory with matching prompt templates in `prompts/`. --- ## AI providers The backend auto-detects available providers from environment variables. No global selector โ€” the model is chosen per corpus from the admin interface. | Provider | Environment variable | Notes | |----------|---------------------|-------| | Google AI Studio | `GOOGLE_AI_STUDIO_API_KEY` | Free tier, good for development | | Vertex AI (service account) | `VERTEX_SERVICE_ACCOUNT_JSON` | Institutional deployments | | Mistral AI | `MISTRAL_API_KEY` | Alternative provider | At least **one** key is required for the pipeline to function. Keys must **never** appear in code, commits, or Docker images. --- ## API reference All endpoints are prefixed with `/api/v1/`. Full OpenAPI docs available at `/docs`. ### Corpus management | Method | Endpoint | Description | |--------|----------|-------------| | `GET` | `/corpora` | List all corpora | | `POST` | `/corpora` | Create a corpus (slug + title + profile) | | `GET` | `/corpora/{id}` | Get a corpus | | `DELETE` | `/corpora/{id}` | Delete a corpus (cascades) | | `GET` | `/corpora/{id}/manuscripts` | List manuscripts in a corpus | ### Ingestion | Method | Endpoint | Description | |--------|----------|-------------| | `POST` | `/corpora/{id}/ingest/iiif-manifest` | Ingest from a IIIF manifest URL | | `POST` | `/corpora/{id}/ingest/iiif-images` | Ingest from direct image URLs | | `POST` | `/corpora/{id}/ingest/files` | Upload image files | ### AI pipeline | Method | Endpoint | Description | |--------|----------|-------------| | `GET` | `/providers` | List detected AI providers | | `GET` | `/providers/{type}/models` | List models for a provider | | `PUT` | `/corpora/{id}/model` | Set AI model for a corpus | | `POST` | `/corpora/{id}/run` | Run pipeline on all pages | | `POST` | `/pages/{id}/run` | Run pipeline on a single page | | `GET` | `/jobs/{id}` | Check job status | | `POST` | `/jobs/{id}/retry` | Retry a failed job | ### Pages and content | Method | Endpoint | Description | |--------|----------|-------------| | `GET` | `/pages/{id}` | Page metadata | | `GET` | `/pages/{id}/master-json` | Full page master (canonical JSON) | | `GET` | `/pages/{id}/layers` | List annotation layers | | `POST` | `/pages/{id}/corrections` | Apply editorial corrections | | `GET` | `/pages/{id}/history` | Version history | | `GET` | `/search?q=` | Full-text search across all pages | ### Export | Method | Endpoint | Description | |--------|----------|-------------| | `GET` | `/manuscripts/{id}/iiif-manifest` | IIIF Presentation 3.0 manifest | | `GET` | `/manuscripts/{id}/mets` | METS XML | | `GET` | `/pages/{id}/alto` | ALTO XML | | `GET` | `/manuscripts/{id}/export.zip` | ZIP bundle (manifest + METS + ALTO) | --- ## Data model Each analyzed page produces a `master.json` โ€” the canonical source of truth for all exports. ``` PageMaster โ”œโ”€โ”€ image โ†’ IIIF service URL, canvas dimensions, provenance โ”œโ”€โ”€ layout โ†’ regions with bounding boxes [x, y, w, h] in absolute pixels โ”œโ”€โ”€ ocr โ†’ diplomatic text, confidence, uncertain segments โ”œโ”€โ”€ translation โ†’ French, English โ”œโ”€โ”€ summary โ†’ short + detailed โ”œโ”€โ”€ commentary โ†’ public, scholarly, sourced claims with certainty levels โ”œโ”€โ”€ extensions โ†’ profile-specific data (iconography, materiality, etc.) โ”œโ”€โ”€ processing โ†’ provider, model, prompt version, timestamp โ””โ”€โ”€ editorial โ†’ status (machine_draft โ†’ validated โ†’ published), version ``` Bounding boxes follow the convention `[x, y, width, height]` in absolute pixels of the original image. Coordinates are automatically scaled from AI analysis space to full canvas dimensions. --- ## IIIF-native image handling IIIF Studio operates in two modes: ### IIIF-native mode (default for manifest/URL ingestion) - Images are **never downloaded or stored** locally - At ingestion: IIIF Image Service URL and canvas dimensions are extracted from the manifest - At analysis: a 1500px derivative is fetched in memory via the IIIF Image API (`{service}/full/!1500,1500/0/default.jpg`), sent to the AI, then discarded - In the viewer: OpenSeadragon loads `info.json` from the IIIF server for native tiled deep zoom - Storage per page: **~5 KB** (JSON metadata only) ### File upload mode (for non-IIIF sources) - Uploaded images are stored locally in `data/corpora/{slug}/` - Derivatives (1500px) and thumbnails (256px) are created on disk - Storage per page: **~50 MB** (images + JSON) --- ## Project structure ``` IIIF-Studio/ โ”œโ”€โ”€ backend/ โ”‚ โ”œโ”€โ”€ app/ โ”‚ โ”‚ โ”œโ”€โ”€ main.py # FastAPI entry point โ”‚ โ”‚ โ”œโ”€โ”€ config.py # Pydantic settings from env vars โ”‚ โ”‚ โ”œโ”€โ”€ api/v1/ # REST endpoints โ”‚ โ”‚ โ”œโ”€โ”€ models/ # SQLAlchemy ORM models โ”‚ โ”‚ โ”œโ”€โ”€ schemas/ # Pydantic v2 schemas (canonical) โ”‚ โ”‚ โ””โ”€โ”€ services/ โ”‚ โ”‚ โ”œโ”€โ”€ ai/ # Provider factory, analyzer, prompt loader โ”‚ โ”‚ โ”œโ”€โ”€ ingest/ # IIIF fetcher, service detection โ”‚ โ”‚ โ”œโ”€โ”€ image/ # Normalizer (in-memory + legacy disk) โ”‚ โ”‚ โ””โ”€โ”€ export/ # ALTO, METS, IIIF manifest generators โ”‚ โ”œโ”€โ”€ tests/ # 585 tests (pytest + pytest-asyncio) โ”‚ โ””โ”€โ”€ pyproject.toml โ”œโ”€โ”€ frontend/ โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”‚ โ”œโ”€โ”€ App.tsx # React Router (/, /admin, /reader, /editor) โ”‚ โ”‚ โ”œโ”€โ”€ lib/api.ts # Typed API client โ”‚ โ”‚ โ”œโ”€โ”€ pages/ # Home, Reader, Editor, Admin โ”‚ โ”‚ โ””โ”€โ”€ components/ # Viewer (OpenSeadragon), retro UI system โ”‚ โ””โ”€โ”€ package.json โ”œโ”€โ”€ profiles/ # 4 corpus profile JSON files โ”œโ”€โ”€ prompts/ # 9 prompt templates organized by profile โ”œโ”€โ”€ Dockerfile # Multi-stage build (Node + Python) โ”œโ”€โ”€ infra/docker-compose.yml # Local development โ””โ”€โ”€ .env.example # Environment variable template ``` --- ## Testing ```bash cd backend pip install -e ".[dev]" pytest tests/ -v --cov=app ``` Expected result: **585 passed, 3 skipped**. All AI calls are mocked in tests โ€” no API keys required to run the test suite. --- ## Deployment ### HuggingFace Spaces This repository is configured for [HuggingFace Spaces](https://huggingface.co/spaces) with Docker SDK on port 7860. AI keys are stored as Space secrets (Settings โ†’ Repository secrets). The CI pipeline (`.github/workflows/`) runs tests on every push and auto-deploys to HuggingFace Spaces on merge to `main`. ### Self-hosted ```bash docker build -t iiif-studio . docker run -p 7860:7860 \ -e GOOGLE_AI_STUDIO_API_KEY=your_key \ -v ./data:/app/data \ iiif-studio ``` --- ## License [Apache License 2.0](LICENSE)