Automatically grade solved MCQ answer sheets from images using Google Gemini 1.5 Vision, displayed through an elegant Gradio web app.
- Overview
- Key Features
- Live Demo (Colab)
- Architecture
- Installation
- Configuration & API Keys
- Running the App
- Output Format
- Project Structure
- Roadmap
- Contributing
- License
- Acknowledgements
MCQ Grading Bot is a lightweight Python application that turns handwritten or printed multiple‑choice answer sheets into structured feedback in seconds. By combining Google Gemini 1.5 Vision’s image‑understanding power with an intuitive Gradio interface, teachers and automated testing systems can:
- Scan a photo of a completed MCQ paper.
- Instantly obtain the student’s name, total questions, correct/wrong counts, score %, and a detailed per‑question breakdown.
- Export or copy results for record‑keeping or analytics workflows.
Average response time is <5 seconds on a Colab GPU (Gemini Flash model, temperature 0.1).
Capability | Details |
---|---|
📸 Image Upload | Accepts PNG/JPG; auto‑converts to bytes for the API. |
🧠 Gemini Vision Grading | Generates a strict JSON report, then prettifies it for display. |
💡 Name Detection | Parses student name from the sheet if present. |
📊 Detailed Analytics | Correct ✓ / wrong ✗ tag on every answer plus overall percentage. |
⚡ Fast & Lightweight | No server‑side storage; everything happens in‑memory. |
🌐 Colab‑Friendly | One‑click run in Google Colab; sharing enabled. |
Launch | Link |
---|---|
click-to-open |
The Colab notebook comes pre‑installed with requirements and uses Colab Secrets so your API keys stay private.
┌───────────────┐ Image (PNG/JPG) ┌──────────────────┐
│ Frontend │ ───────────────────────►│ Gemini Vision │
│ (Gradio UI) │◄──────── Report JSON ── │ (1.5‑Flash) │
└─────▲─┬───────┘ └────────▲─────────┘
│ | Prettify + Stats |
│ └───────────────────────────────────────────┘
│ Backend (Fast in‑memory)
└────────── Results to User (Markdown Textbox)
-
Clone the repo
git clone https://github.com/choudaryhussainali/MCQ_Grading_Bot.git cd MCQ_Grading_Bot
-
Create a virtual environment (optional)
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
The app needs Google Gemini (and optionally Groq) API keys.
Variable | Description | Required |
---|---|---|
GEMINI_API_KEY |
Key for Gemini 1.5 Vision | ✅ |
GROQ_API_KEY |
Key for Groq LLMs (future use) | ⬜ |
### Option A — Colab Secrets
from google.colab import userdata
# then access with userdata.get("GEMINI_API_KEY")
### Option B — Environment File
Create a .env
in project root:
GEMINI_API_KEY=your_gemini_key_here
GROQ_API_KEY=your_groq_key_here
pip install python-dotenv
The script will fall back to os.getenv()
if google.colab
isn’t present.
python mcq_grading_bot.py # or the filename you saved
The terminal prints a local URL (e.g. http://127.0.0.1:7860). Open it in your browser, upload an MCQ sheet image, and click “Grade Answers”.
Internally the bot expects Gemini to return pure JSON:
This is parsed and rendered as a neat, human‑readable Markdown report in the Gradio textbox.
MCQ_Grading_Bot/
├─ mcq_grading_bot.py # Main Gradio app
├─ requirements.txt
├─ screenshots/
│ └─ demo.png # UI screenshot
├─ .env.example # Sample env file
└─ README.md
- CSV / PDF export of grading results
- Bulk image upload & batch grading
- Integration with LMS APIs (Moodle, Canvas)
- UI theme switcher (light/dark)
- Automated unit tests & CI workflow
Pull requests are welcome!
- Fork the repo
- Create a feature branch:
git checkout -b feat/your‑feature
- Commit & push:
git commit -m "Add feature"
- Open a PR describing your changes.
Please run black
and flake8
before submitting.
This project is proprietary and confidential. All rights reserved.
© 2025 HUSSAIN ALI. This code may not be copied, modified, distributed, or used without explicit permission.
For questions or collaboration requests:
- 📧 Email: choudaryhussainali@outlook.com
- 🌐 GitHub: choudaryhussainali
- Google Generative AI Python SDK
- Gradio
- Pillow
- Inspired by educators streamlining assessment workflows.
Happy grading! If this project helps you, please ⭐️ the repo and share feedback.