GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Flynntaggart26/PDF-quiz: Turn any PDF into a high-yield study outline and interactive MCQ quiz with any OpenAI-compatible LLM.

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
prompts
prompts
 
 
src/pdf_quiz
src/pdf_quiz
 
 
tests
tests
 
 
.dockerignore
.dockerignore
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
Dockerfile
Dockerfile
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

PDF-Quiz

Turn any text-based PDF into a high-yield study outline and an interactive-ready MCQ quiz using any OpenAI-compatible LLM (OpenAI, OpenRouter, Ollama, LM Studio, …).

PDF → extracted text → study outline (Markdown) → quiz (Markdown or JSON)

Use it as a web app (no coding) or as a CLI / Python library.

Features

  • High-yield outline — core frameworks, definitions, methodologies, causal links; fluff removed.
  • Two quiz modes
    • markdown — human-readable Q&A with answer key (study sheets, printing).
    • json — pure JSON for frontends, validated against a strict schema (no prose, no code fences).
  • Rigorous quiz prompt — truth-to-source constraint: every question verifiable from the text, plausible distractors, educational explanations.
  • --strict Structured Outputs — passes a Pydantic Quiz model as response_format for 100% schema compliance (OpenAI gpt-4o-mini and newer); automatic fallback to JSON mode on servers without .parse support.
  • Long-PDF handling — outlines are chunked (~12k chars) and merged; quiz input capped at ~15k chars (or use --quiz-from-outline).
  • Pluggable backend — one client, configured entirely by LLM_BASE_URL / LLM_API_KEY / LLM_MODEL.

Requirements

  • Python 3.10+
  • An API key for your provider (or a local server needing no key)

Quickstart

# 1. Clone and set up
git clone https://github.com/Flynntaggart26/PDF-quiz.git
Set-Location PDF-quiz
python -m venv .venv; .\.venv\Scripts\Activate.ps1
pip install -e .

# 2. Configure the model
Copy-Item .env.example .env
# edit .env: LLM_API_KEY, LLM_BASE_URL, LLM_MODEL

# 3. Run
python -m pdf_quiz.cli "path\to\lecture.pdf" --format json -n 10
# (in a venv, the shorter `pdf-quiz` command works too)

Web app (easiest)

streamlit run src/pdf_quiz/app.py

Upload a PDF in the browser, tune questions in the sidebar, read the outline, answer the quiz interactively with instant scoring, and download the JSON. Your API key can be entered in the sidebar — it's never written to disk.

Docker alternative (full guide: docs/DOCKER.md):

docker build -t pdf-quiz .
docker run -p 8501:8501 -e LLM_API_KEY=sk-... pdf-quiz

Outputs land in output/:

File Contents
<name>_extracted.txt Raw text pulled from the PDF
<name>_outline.md High-yield study guide (Prompt #1)
<name>_quiz.md Markdown quiz + answer key (--format markdown)
<name>_quiz.json Validated quiz JSON (--format json)

Configuration

All settings come from the environment (.env supported):

Variable Default Example
LLM_MODEL gpt-4o-mini gpt-4o, llama3.1:8b
LLM_API_KEY not-needed sk-…
LLM_BASE_URL OpenAI default https://openrouter.ai/api/v1, http://localhost:11434/v1

Provider presets (set in .env):

# OpenAI
LLM_BASE_URL=https://api.openai.com/v1
LLM_MODEL=gpt-4o-mini
LLM_API_KEY=sk-your-key

# OpenRouter
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_MODEL=openai/gpt-4o-mini
LLM_API_KEY=sk-or-your-key

# Local Ollama (no key needed)
LLM_BASE_URL=http://localhost:11434/v1
LLM_MODEL=llama3.1:8b
LLM_API_KEY=not-needed

--strict (Structured Outputs) requires a server that supports chat.completions.parse — OpenAI gpt-4o-mini/gpt-4o and newer. Ollama and most proxies fall back to JSON mode automatically.

Usage

# Full pipeline: outline + quiz
python -m pdf_quiz.cli "lecture.pdf" -n 10

# Frontend-ready JSON quiz
python -m pdf_quiz.cli "lecture.pdf" --format json -n 10

# Guaranteed schema via Structured Outputs (with fallback)
python -m pdf_quiz.cli "lecture.pdf" --format json --strict -n 10

# Outline only / quiz only
python -m pdf_quiz.cli "lecture.pdf" --outline-only
python -m pdf_quiz.cli "lecture.pdf" --quiz-only -n 15

# Cheaper quiz grounded in the outline instead of raw text
python -m pdf_quiz.cli "lecture.pdf" --format json --quiz-from-outline

# Custom output dir / extra retries on flaky models
python -m pdf_quiz.cli "lecture.pdf" -o my_notes --format json --retries 4

Full flags: python -m pdf_quiz.cli --help (or pdf-quiz --help in a venv). Quiz generation retries automatically (default 2) when the model returns invalid JSON, feeding the validation errors back for correction.

Tests

pytest -q

CI (.github/workflows/ci.yml) runs the suite on Python 3.10–3.12 for every push and pull request.

JSON contract (frontend)

--format json emits exactly this shape — validated before it's written, so your UI can trust it:

{
  "quiz_title": "Cell Biology Basics",
  "questions": [
    {
      "id": 1,
      "question": "Which organelle produces most of the cell's ATP?",
      "options": ["Nucleus", "Mitochondrion", "Ribosome", "Golgi apparatus"],
      "correct_answer": "Mitochondrion",
      "explanation": "The text states mitochondria carry out oxidative phosphorylation to produce ATP."
    }
  ]
}

Rules enforced by validate_quiz_json() (src/pdf_quiz/generator.py:67):

  • quiz_title: non-empty string.
  • Exactly N questions, id sequential from 1.
  • options: exactly 4 distinct non-empty strings.
  • correct_answer: byte-exact match of one option.
  • explanation: non-empty.
  • Markdown fences (```json) stripped automatically; non-JSON output rejected with a clear error.

Minimal frontend consumption:

const quiz = await fetch("lecture_quiz.json").then(r => r.json());
quiz.questions.forEach(q => {
  // q.question, q.options[4], q.correct_answer, q.explanation
});

Python API

from pdf_quiz.extractor import extract_pdf_text
from pdf_quiz.generator import generate_outline, generate_quiz_json, generate_quiz_structured

text = extract_pdf_text("lecture.pdf")
outline = generate_outline(text)
quiz = generate_quiz_json(text, num_questions=10)          # works on any backend
quiz = generate_quiz_structured(text, num_questions=10)    # Structured Outputs + fallback

Project structure

prompts/
  01_high_yield_outline.md    # Prompt #1: executive summary + core concepts
  02_quiz_generator.md        # Markdown quiz variant
  02_quiz_generator_json.md   # Prompt #2: rigorous psychometrician, pure-JSON
src/pdf_quiz/
  app.py        # Streamlit web UI
  cli.py        # argument parsing + pipeline orchestration (`pdf-quiz`)
  extractor.py  # pypdf text extraction + chunking
  generator.py  # outline map-reduce, quiz render/validate/parse + retries
  llm.py        # OpenAI-compatible client (json_mode + complete_structured)
  schemas.py    # Pydantic Question / Quiz contract
tests/          # pytest suite (no API calls) — run with `pytest -q`

Prompts are plain Markdown with {{PLACEHOLDERS}} — edit them without touching code.

License

MIT — see LICENSE.

Limitations

  • Text PDFs only. Scanned/image PDFs have no text layer and exit with No extractable text found — run OCR (e.g. ocrmypdf) first.
  • Quiz input cap. Raw text over ~15k chars is truncated for the quiz call; use --quiz-from-outline for long documents.
  • --strict support. Only backends implementing chat.completions.parse honor it; everything else uses response_format: json_object + validation.
  • LLM accuracy. The prompt constrains the model to the source text, but always spot-check high-stakes material.

About

Turn any PDF into a high-yield study outline and interactive MCQ quiz with any OpenAI-compatible LLM.

Topics

e-learningeducationllmmcqollamaopenaipdfpydanticpythonquiz-generatorstreamlitstudy-tool

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.