Spaces:
Sleeping
title: Quiz Generation
emoji: 📝
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
AI Exam Generator
A FastAPI-based microservice that generates quizzes from uploaded documents using an AI model.
The API accepts PDF, DOCX, or TXT files, extracts their text, and generates different types of questions such as:
- Multiple Choice Questions (MCQ)
- Fill in the Blank
- Explanation Questions
The questions are generated using the Groq LLM (Llama 3.3 70B) via LangChain.
FEATURES
- Upload documents (PDF, DOCX, TXT)
- Automatic text extraction
- AI-generated quizzes
- Multiple question types
- Separate answer key generation
- Optional download as TXT or PDF
- REST API with FastAPI
- Interactive API documentation
INSTALLATION
- Clone the repository
- Create a virtual environment
python -m venv .venv - Activate the environment (Windows PowerShell)
.\.venv\Scripts\Activate.ps1 - Install dependencies
pip install -r requirements.txt
ENVIRONMENT VARIABLES
Create a .env file in the project root:
MY_API_KEY=your_groq_api_key_here
This key is required to access the Groq LLM.
RUNNING THE API
Start the server:
uvicorn app.main:app --reload
The API will run at:
http://127.0.0.1:8000
Interactive API documentation:
http://127.0.0.1:8000/docs
API ENDPOINTS
POST /api/v1/uploadUpload a document (PDF, DOCX, TXT)POST /api/v1/generateGenerate questions from uploaded textGET /api/v1/quiz/{quiz_id}Returns generated quiz with answer keyGET /api/v1/download/{filename}Download generated quiz fileGET /api/v1/uploadsList uploaded documentsDELETE /api/v1/upload/{upload_id}Delete uploaded document
EXAMPLE WORKFLOW
- Upload a file
- Generate a quiz
- Retrieve the quiz results
TECHNOLOGIES USED
FastAPI, LangChain, Groq LLM (Llama 3.3 70B), Python, pdfplumber, python-docx, FPDF
NOTES
- Uploaded text and quizzes are stored locally in JSON files.
- This implementation uses in-memory storage.
- For production use, a database is recommended.