An intelligent tutoring system powered by Retrieval-Augmented Generation (RAG) that provides Q&A functionality and automatic quiz generation from PDF documents.
- 📚 Document Management: Upload and manage PDF documents
- 💬 Q&A System: Ask questions about uploaded documents using RAG with real-time HTMX updates
- 📝 QCM Generation: Automatically generate multiple-choice questions (MCQ) from documents
- 📊 White Tests: Create comprehensive tests covering multiple topics
- 🌐 Bilingual Support: Supports both English and French
- 🚀 GPU Optimized: 4-bit quantization for efficient model loading
- 🎨 Modern UI: Glass morphism design with gradient backgrounds and smooth animations
- ⚡ Real-time Updates: HTMX-powered chat interface for instant responses
- 📱 Responsive Design: Works seamlessly on desktop and mobile devices
-
Backend: FastAPI with RAG pipeline
- Mistral-7B-Instruct for Q&A
- Phi-3-mini for QCM generation
- BGE-M3 for embeddings
- FAISS for vector storage
-
Frontend: Django web application
- Python 3.11+
- CUDA-capable GPU (recommended, but CPU works too)
- 16GB+ RAM (32GB recommended)
- At least 20GB free disk space for models
Run the automated setup script:
Windows:
setup.batThis will create all virtual environments, install dependencies, and run initial migrations.
- ✅ Automated Setup: Added
setup.batscript for Windows to automate environment creation and dependency installation - ✅ Fixed Dependencies: Added missing
spacypackage to backend requirements - ✅ Enhanced Error Handling: Improved exception handling across all API endpoints
- ✅ Basic Testing: Added initial test suite for API endpoints
- ✅ Modern UI/UX: Complete frontend redesign with:
- Glass morphism effects and gradient backgrounds
- HTMX for real-time chat updates without page refreshes
- Enhanced loading indicators and animations
- Responsive design with modern styling
- Improved accessibility and user feedback
If you prefer manual setup, follow these steps:
- Clone the repository:
cd backend- Create virtual environment:
python -m venv venv_backend
source venv_backend/bin/activate # On Windows: venv_backend\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your preferred settings- Download models (first run will download automatically): The models will be downloaded from HuggingFace on first run:
mistralai/Mistral-7B-Instruct-v0.3(~14GB)microsoft/Phi-3-mini-4k-instruct(~7GB)BAAI/bge-m3(~600MB)BAAI/bge-reranker-v2-m3(~400MB)
- Create data folder:
mkdir data
# Add your PDF files to the data folder- Run the backend:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8001The API will be available at http://localhost:8001
API Documentation: http://localhost:8001/docs
- Navigate to frontend:
cd frontend- Create virtual environment:
python -m venv venv_frontend
source venv_frontend/bin/activate # On Windows: venv_frontend\Scripts\activate- Install dependencies:
pip install -r requirements.txt-
Configure backend URL: Update
core/utils.pywith your backend API URL if different from default. -
Run migrations:
python manage.py migrate- Create superuser (optional):
python manage.py createsuperuser- Run the frontend:
python manage.py runserverFrontend will be available at http://localhost:8000
Key configuration options in backend/.env:
DATA_FOLDER: Folder containing PDF documents (default:data)MAX_FILE_SIZE_MB: Maximum file upload size (default:10)USE_4BIT: Use 4-bit quantization (default:true)DEVICE: Device selection -auto,cuda, orcpu(default:auto)ALLOWED_ORIGINS: CORS allowed origins (comma-separated)
You can change models in .env:
QA_MODEL: Model for Q&A (default:mistralai/Mistral-7B-Instruct-v0.3)QCM_MODEL: Model for quiz generation (default:microsoft/Phi-3-mini-4k-instruct)EMBEDDING_MODEL: Embedding model (default:BAAI/bge-m3)RERANKER_MODEL: Reranking model (default:BAAI/bge-reranker-v2-m3)
POST /qa/ask- Ask a question about documents
POST /qcm/generate- Generate QCM for a topicPOST /qcm/white-test- Generate white test for multiple topics
POST /documents/upload- Upload PDF documentsGET /documents/list- List uploaded documentsDELETE /documents/delete/{filename}- Delete a document
GET /health- Check system health and model status
See full API documentation at /docs endpoint.
curl -X POST "http://localhost:8001/qa/ask" \
-H "Content-Type: application/json" \
-d '{"query": "What is machine learning?"}'curl -X POST "http://localhost:8001/qcm/generate" \
-H "Content-Type: application/json" \
-d '{
"topic": "Machine Learning",
"num_questions": 5,
"lang": "en"
}'curl -X POST "http://localhost:8001/documents/upload" \
-F "files=@document.pdf"ai_tutoring_system/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI app entry point
│ │ ├── config.py # Configuration management
│ │ ├── routers/ # API route handlers
│ │ │ ├── ask.py # Q&A endpoints
│ │ │ ├── qcm.py # Quiz generation endpoints
│ │ │ ├── documents.py # Document management
│ │ │ └── health.py # Health checks
│ │ ├── schemas/ # Pydantic models
│ │ └── utils/
│ │ └── rag_pipeline.py # Core RAG logic
│ ├── data/ # PDF documents storage
│ ├── requirements.txt # Python dependencies
│ └── .env.example # Environment template
├── frontend/
│ ├── core/ # Django app
│ ├── templates/ # HTML templates
│ └── manage.py
└── README.md # This file
- Enable 4-bit quantization: Set
USE_4BIT=truein.env - Use CPU: Set
DEVICE=cpuin.env - Reduce batch sizes in
config.py
- Check internet connection
- Verify HuggingFace access (some models may require authentication)
- Models are cached, so download happens only once
- Ensure PDF files are valid and not corrupted
- Check that
DATA_FOLDERexists and is readable - Verify sufficient disk space
- GPU Memory: Use 4-bit quantization (
USE_4BIT=true) for models - CPU Memory: Force embeddings to CPU (already configured)
- Batch Processing: Documents are processed in batches automatically
- Caching: Models and embeddings are cached for faster subsequent runs
# Backend tests
cd backend
venv_backend\Scripts\activate
python -m pytest tests/ -v
# Frontend tests (when implemented)
cd frontend
venv_frontend\Scripts\activate
python manage.py testThe project follows PEP 8 guidelines. Consider using:
blackfor code formattingflake8orpylintfor lintingmypyfor type checking
[Add your license here]
[Add contributing guidelines here]
For issues and questions, please open an issue on the repository.