Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ PDF Genius - Chat with PDFs

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).

πŸš€ Features

  • 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

πŸ› οΈ Tech Stack

  • 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

πŸ“‹ Prerequisites

  • Python 3.8+
  • OpenAI API key
  • Git (for version control)

πŸ”§ Installation & Setup

1. Clone the Repository

git clone <your-repository-url>
cd pdfchat

2. Create Virtual Environment

python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Environment Variables

# Copy the template and fill in your values
cp .env.template .env
# Edit .env file with your actual values

Required environment variables:

  • SECRET_KEY: Django secret key
  • OPENAI_API_KEY: Your OpenAI API key
  • DEBUG: Set to True for development

5. Database Setup

python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

6. Run Development Server

python manage.py runserver

Visit http://127.0.0.1:8000 to access the application.

πŸ“ Project Structure

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

πŸ—„οΈ Database Models

PDFDocument

  • User association
  • File metadata (title, size, pages)
  • Processing status
  • Upload timestamp

TextChunk

  • Document association
  • Text content
  • Chunk index and page number
  • Embedding status

ChatSession

  • User and document association
  • Session metadata
  • Creation timestamp

Message

  • Session association
  • User questions and AI responses
  • Timestamp and metadata

πŸ”„ Development Workflow

Follow the detailed development plan in development_plan.md:

Phase 1: Foundation Setup

  1. Environment and dependencies
  2. Django configuration
  3. Database models

Phase 2: Core Backend

  1. PDF upload system
  2. Text extraction pipeline
  3. Database implementation

Phase 3: AI Integration

  1. OpenAI API setup
  2. Embedding generation
  3. Vector database (FAISS)
  4. RAG pipeline

Phase 4: Frontend

  1. Base templates
  2. Authentication system
  3. Core application pages
  4. Interactive features

Phase 5: Advanced Features

  1. Chat enhancements
  2. PDF management features
  3. AI response improvements
  4. User experience enhancements

Phase 6: Testing

  1. Unit testing
  2. Integration testing
  3. Performance testing
  4. Security testing

Phase 7: Deployment

  1. Production configuration
  2. Platform deployment
  3. Monitoring setup

πŸ§ͺ Testing

# 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 report

πŸš€ Deployment

Environment Variables for Production

SECRET_KEY=your-production-secret-key
DEBUG=False
ALLOWED_HOSTS=yourdomain.com
DATABASE_URL=your-postgresql-url
OPENAI_API_KEY=your-openai-api-key

Platform-Specific Instructions

Railway

  1. Connect your GitHub repository
  2. Set environment variables in Railway dashboard
  3. Deploy automatically from main branch

Render

  1. Create new web service
  2. Connect repository
  3. Configure build and start commands
  4. Set environment variables

PythonAnywhere

  1. Upload code to server
  2. Configure WSGI file
  3. Set up virtual environment
  4. Configure static files

πŸ“š API Documentation

RAG Service Methods

# 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)

PDF Processing Pipeline

# 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)

πŸ”’ Security Considerations

  • File upload validation (type, size)
  • User authentication and authorization
  • CSRF protection on all forms
  • Secure API key storage
  • SQL injection prevention
  • XSS protection

πŸ“ˆ Performance Optimization

  • Database indexing for faster queries
  • Efficient vector similarity search
  • Batch processing for embeddings
  • Caching for frequently accessed data
  • Optimized file storage

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenAI for GPT and embedding APIs
  • LangChain for RAG framework
  • FAISS for vector similarity search
  • Django community for excellent framework

πŸ“ž Support

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! πŸš€

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages