A comprehensive Django web application that allows users to upload PDF files and interact with them through an AI-powered chat interface using Retrieval-Augmented Generation (RAG).
- PDF Upload & Management: Upload PDFs up to 10MB with file validation
- AI-Powered Chat: Ask questions about your PDF content and get intelligent answers
- User Authentication: Secure user registration and login system
- Chat History: Save and access previous conversations
- Responsive Design: Mobile-friendly interface using Bootstrap/Tailwind CSS
- Vector Search: Efficient semantic search using FAISS
- RAG Pipeline: Advanced retrieval-augmented generation for accurate answers
- Backend: Django 5.2.5
- Frontend: Django Template Language (DTL) + HTML/CSS/JavaScript
- AI/ML: OpenAI API, LangChain, FAISS
- PDF Processing: PyPDF2, pdfplumber
- Database: SQLite (development) / PostgreSQL (production)
- Styling: Bootstrap 5 / Tailwind CSS
- Deployment: Railway/Render/PythonAnywhere
- Python 3.8+
- OpenAI API key
- Git (for version control)
git clone <your-repository-url>
cd pdfchatpython -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activatepip install -r requirements.txt# Copy the template and fill in your values
cp .env.template .env
# Edit .env file with your actual valuesRequired environment variables:
SECRET_KEY: Django secret keyOPENAI_API_KEY: Your OpenAI API keyDEBUG: Set to True for development
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuserpython manage.py runserverVisit http://127.0.0.1:8000 to access the application.
pdfchat/
βββ manage.py
βββ requirements.txt
βββ .env.template
βββ development_plan.md
βββ pdfchat/
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ pdf_app/ # Main application (to be created)
β βββ models.py # Database models
β βββ views.py # View functions
β βββ forms.py # Django forms
β βββ urls.py # URL patterns
β βββ services/ # Business logic
β βββ pdf_processor.py
β βββ embedding_service.py
β βββ rag_service.py
βββ templates/ # HTML templates
β βββ base.html
β βββ home.html
β βββ dashboard.html
β βββ upload.html
β βββ chat.html
βββ static/ # CSS, JS, Images
βββ media/ # Uploaded files
βββ tests/ # Test files
- User association
- File metadata (title, size, pages)
- Processing status
- Upload timestamp
- Document association
- Text content
- Chunk index and page number
- Embedding status
- User and document association
- Session metadata
- Creation timestamp
- Session association
- User questions and AI responses
- Timestamp and metadata
Follow the detailed development plan in development_plan.md:
- Environment and dependencies
- Django configuration
- Database models
- PDF upload system
- Text extraction pipeline
- Database implementation
- OpenAI API setup
- Embedding generation
- Vector database (FAISS)
- RAG pipeline
- Base templates
- Authentication system
- Core application pages
- Interactive features
- Chat enhancements
- PDF management features
- AI response improvements
- User experience enhancements
- Unit testing
- Integration testing
- Performance testing
- Security testing
- Production configuration
- Platform deployment
- Monitoring setup
# Run all tests
python manage.py test
# Run specific test file
python manage.py test pdf_app.tests.test_models
# Run with coverage
pip install coverage
coverage run --source='.' manage.py test
coverage reportSECRET_KEY=your-production-secret-key
DEBUG=False
ALLOWED_HOSTS=yourdomain.com
DATABASE_URL=your-postgresql-url
OPENAI_API_KEY=your-openai-api-key- Connect your GitHub repository
- Set environment variables in Railway dashboard
- Deploy automatically from main branch
- Create new web service
- Connect repository
- Configure build and start commands
- Set environment variables
- Upload code to server
- Configure WSGI file
- Set up virtual environment
- Configure static files
# Generate embeddings for text chunks
embeddings = EmbeddingService.generate_embeddings(text_chunks)
# Search for similar content
results = RAGService.search_similar_chunks(query, top_k=5)
# Generate AI response
response = RAGService.generate_response(question, context)# Extract text from PDF
text = PDFProcessorService.extract_text(pdf_file)
# Chunk text for processing
chunks = PDFProcessorService.chunk_text(text)
# Process and store chunks
PDFProcessorService.process_chunks(chunks, document_id)- File upload validation (type, size)
- User authentication and authorization
- CSRF protection on all forms
- Secure API key storage
- SQL injection prevention
- XSS protection
- Database indexing for faster queries
- Efficient vector similarity search
- Batch processing for embeddings
- Caching for frequently accessed data
- Optimized file storage
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for GPT and embedding APIs
- LangChain for RAG framework
- FAISS for vector similarity search
- Django community for excellent framework
For questions and support:
- Check the development plan in
development_plan.md - Review the project specification in
PDF_Genius_Project_Spec.md - Open an issue for bugs or feature requests
Ready to build your PDF chat application? Start with Phase 1 in the development plan! π