You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.11+
Google Gemini API Key (free) → https://aistudio.google.com/app/apikey
Installation
# 1️⃣ Clone the repository
git clone https://github.com/YOUR_USERNAME/stem-mcq-generator.git
cd stem-mcq-generator
# 2️⃣ Create virtual environment
python -m venv venv
# Activate (Linux/Mac)source venv/bin/activate
# Activate (Windows)
venv\Scripts\activate
# 3️⃣ Install dependencies
pip install -r requirements.txt
# 4️⃣ Configure environment
cp .env.example .env
# Open .env and add your GEMINI_API_KEY# 5️⃣ Run the server
uvicorn app.main:app --reload
# 6️⃣ Open interactive API docs# 👉 http://localhost:8000/docs
💡 No API key? App runs in mock mode automatically — perfect for testing!
🐳 Docker Deployment
# 1️⃣ Clone & configure
git clone https://github.com/YOUR_USERNAME/stem-mcq-generator.git
cd stem-mcq-generator
cp .env.example .env
# Add GEMINI_API_KEY to .env# 2️⃣ Build and run
docker-compose up --build
# 3️⃣ Access# 👉 http://localhost:8000/docs
📡 API Endpoints
🔵 Generate
Method
Endpoint
Description
POST
/api/v1/generate/topic
Generate MCQs from a topic string
POST
/api/v1/generate/pdf
Generate MCQs from uploaded PDF file
🟢 Retrieve & Validate
Method
Endpoint
Description
GET
/api/v1/mcq/{set_id}
Retrieve MCQ set by ID
POST
/api/v1/validate
Submit answers → get score + grade
🟡 Export
Method
Endpoint
Description
GET
/api/v1/export/{id}/json
Download as JSON
GET
/api/v1/export/{id}/csv
Download as CSV (Excel-compatible)
GET
/api/v1/export/{id}/text
Download as printable text
⚪ Utility
Method
Endpoint
Description
GET
/api/v1/subjects
List all supported subjects
GET
/api/v1/difficulties
List difficulty levels with descriptions
GET
/health
API health check
GET
/docs
Interactive Swagger UI
🎯 Supported Subjects & Difficulty Levels
📚 Subjects
Subject
Value
Example Topics
⚛️ Physics
physics
Newton's Laws, Thermodynamics, Optics
🧪 Chemistry
chemistry
Periodic Table, Chemical Bonding, Reactions
➕ Mathematics
mathematics
Calculus, Algebra, Trigonometry
🧬 Biology
biology
DNA Replication, Photosynthesis, Cell Division
💻 Computer Science
computer_science
Binary Trees, Sorting, OOP
🔬 General Science
general_science
Mixed STEM topics
🎯 Difficulty Levels
Level
Target Audience
Question Style
🟢 easy
Class 6–8
Basic recall, definitions, simple facts
🟡 medium
Class 9–12
Application, understanding, diagrams
🔴 hard
JEE / NEET / GATE
Analysis, numerical problems, evaluation
🧪 Running Tests
# Run all tests
pytest tests/ -v
# Run with coverage report
pytest tests/ -v --cov=app --cov-report=html
# Run specific test class
pytest tests/test_api.py::TestGenerate -v
🧾 Test Coverage
Test Class
Tests
Coverage
TestHealth
2
Health endpoints
TestGenerate
5
MCQ generation (topic + PDF)
TestMCQStructure
3
Question format validation
TestRetrieval
2
Get by ID, 404 handling
TestValidation
3
Score, grade, answer checking
TestExport
3
JSON, CSV, text export
TestUtility
2
Subjects & difficulties list
Total
20+
Full API coverage
🛠️ Tech Stack
Layer
Technology
Purpose
🌐 Framework
FastAPI 0.115
REST API with async support
🤖 AI / LLM
Google Gemini 1.5 Flash
MCQ generation
📄 PDF
PyMuPDF (fitz)
Text extraction
✅ Validation
Pydantic v2
Request/response schemas
🧪 Testing
pytest + httpx
20+ test cases
🐳 Deployment
Docker + Compose
Containerized deployment
📖 API Docs
Swagger UI
Auto-generated interactive docs
🔑 Environment Variables
# RequiredGEMINI_API_KEY=your_google_gemini_api_key# OptionalLLM_PROVIDER=gemini# gemini | openaiENVIRONMENT=development# development | productionMAX_NUM_QUESTIONS=50TEMPERATURE=0.7MAX_FILE_SIZE_MB=10RATE_LIMIT_PER_MINUTE=20
🗺️ Roadmap
Topic-based MCQ generation
PDF upload & text extraction
Answer validation with scoring
JSON / CSV / Text export
Docker deployment
🔜 Redis for persistent storage
🔜 Streamlit frontend UI
🔜 JWT user authentication
🔜 Hindi language support
🔜 Image-based questions
🔜 Bulk topic generation
🔜 Leaderboard & quiz sessions
🤝 Contributing
Contributions are welcome! 🎉
# 1. Fork the repo# 2. Create your feature branch
git checkout -b feature/amazing-feature
# 3. Commit your changes
git commit -m "✨ Add amazing feature"# 4. Push to branch
git push origin feature/amazing-feature
# 5. Open a Pull Request
📄 License
Distributed under the MIT License. See LICENSE for more information.
👤 Author
Saranay
AI/ML Professional · STEM Educator · Python Developer