Skip to main content

Convert images (screenshots, scanned pages, diagrams) into MCQ questions using AI

Project description

image2mcq

Convert images — screenshots, scanned pages, diagrams, charts, and photographs — into high-quality MCQ questions using AI.

Built on top of html2mcq's image pipeline, extracted as a standalone library focused purely on image-to-MCQ generation.


Features

  • Two processing methods:
    • twostep (default) — OCR image text, then generate MCQs from extracted text
    • images2mcq — send images directly to a vision LLM for MCQ generation
  • Multiple AI providers: OpenRouter, Anthropic, OpenAI, Ollama
  • Auto model failover: if one model fails (e.g. quota exhausted), automatically tries the next
  • Local OCR fallback: Tesseract OCR when vision APIs are unavailable
  • CLI & Python API — use from terminal or integrate into your code

Quick Start

CLI

# Single image file
image2mcq --image-path diagram.png -n 5

# Multiple image URLs
image2mcq --image-url https://example.com/chart1.png --image-url https://example.com/chart2.png

# Scan a folder of images
image2mcq --image-folder ./lecture-slides/ --method images2mcq

# Output as JSON
image2mcq --image-path notes.png -o questions.json --format json

# Use n=999 to generate as many as the content supports
image2mcq --image-path textbook-page.png

Python API

from image2mcq import ImageMCQGenerator

gen = ImageMCQGenerator(
    api_key="sk-or-v1-...",
    provider="openrouter",
    mcq_model="google/gemini-2.5-flash-lite",
)

# From local files
mcq = gen.from_image_paths("screenshot.png", n=5)
print(mcq.to_pretty_str())

# From URLs
mcq = gen.from_image_urls("https://example.com/diagram.png", n=3)
print(mcq.to_json())

# From multiple images
mcq = gen.from_image_paths(["page1.png", "page2.png", "page3.png"])

Two-Step (OCR → MCQ)

gen = ImageMCQGenerator(
    api_key="sk-or-v1-...",
    method="twostep",  # default
)
mcq = gen.from_image_paths("scanned-page.png", n=10)

Images2MCQ (Vision Direct)

gen = ImageMCQGenerator(
    api_key="sk-or-v1-...",
    method="images2mcq",
    mcq_model="openai/gpt-4o",  # vision model
)
mcq = gen.from_image_paths("architecture-diagram.png", n=5)

Custom Instructions

mcq = gen.from_image_paths(
    "graph.png",
    n=5,
    difficulty_mix="50% easy, 50% hard",
    focus_topics=["data structures", "time complexity"],
    custom_instructions="Make answers very close and confusing",
)

Auto Model Selection

gen = ImageMCQGenerator(
    api_key="sk-or-v1-...",
    mcq_model="auto",
    mcq_model_list=[
        "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free",
        "google/gemma-4-31b-it:free",
    ],
)

Environment Variables

Variable Purpose
OPENROUTER_API_KEY Default API key for OpenRouter
ANTHROPIC_API_KEY API key for Anthropic
OPENAI_API_KEY API key for OpenAI
IMAGE2MCQ_MCQ_MODELS Comma-separated MCQ model priority list for model="auto"
IMAGE2MCQ_OCR_MODELS Comma-separated OCR model priority list for ocr_model="auto"

Output Format

# Pretty-print
print(mcq.to_pretty_str())

# JSON
print(mcq.to_json())
# {
#   "total_exam_time": 20,
#   "questions": [
#     {
#       "question_html": "What is the time complexity of binary search?",
#       "options": ["O(n)", "O(log n)", "O(n^2)", "O(1)"],
#       "answers": [1],
#       "multi": false,
#       "marks": 1.0,
#       "negative_marks": 0.25,
#       "difficulty": "easy",
#       "explaination": "Binary search halves the search space each iteration."
#     }
#   ]
# }

Installation

pip install image2mcq

For OCR support, also install Tesseract.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image2mcq-1.1.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

image2mcq-1.1.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file image2mcq-1.1.1.tar.gz.

File metadata

  • Download URL: image2mcq-1.1.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for image2mcq-1.1.1.tar.gz
Algorithm Hash digest
SHA256 cf0d1c38f3a9f82fba76a434f0fbf47581771c3d0bd65ad06c83a0c3ffd36487
MD5 14aca5992e5963fad5ef9bb1f159068f
BLAKE2b-256 1dc4a6c66035ec2649c6170898828814b58ae62f32d36bbdd2be629c7dbf5e2a

See more details on using hashes here.

File details

Details for the file image2mcq-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: image2mcq-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for image2mcq-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c17204a0ebf4091a0a51f91fd59452a535f918a1b299e5e470367a7e9c52cc14
MD5 41c69198aea7f126cfd80fad5c956bcb
BLAKE2b-256 7a8c2d6dcc3e0974f2f350082cc55a2440415b761b53709dc78e3d401cb53355

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page