Transform your PDF documents into immersive, AI-illustrated digital books with thematic marginalia artwork.
- PDF Text Extraction: Advanced text extraction with coordinate mapping using PyMuPDF
- AI Content Analysis: Intelligent genre, theme, and mood detection using Google Gemini API
- Thematic Marginalia: AI-generated decorative artwork positioned in book margins
- Immersive Reading Experience: Beautiful book-style interface with page-turning animations
- Real-time Processing: Progress tracking during PDF analysis and enhancement
- Responsive Design: Works seamlessly on desktop and mobile devices
The application processes PDFs and creates an interactive book reader experience:
- Upload any PDF document
- AI analyzes content for genre, themes, and emotional tone
- Generates thematic artwork for margins
- Presents content in an immersive book interface
- Python 3.11+
- PostgreSQL database (or SQLite for development)
- Google Gemini API key (optional - falls back to high-quality mock responses)
-
Clone this repository:
git clone https://github.com/JC230903/PageGenie.git cd PageGenie -
Install dependencies:
pip install -r requirements.txt
Or if using uv (recommended):
uv sync
-
Set up environment variables: Create a
.envfile in the project root:DATABASE_URL=postgresql://user:password@localhost/dbname GEMINI_API_KEY=your_gemini_api_key_here SESSION_SECRET=your_secret_key_for_sessions
-
Initialize the database:
python -c "from app import app, db; app.app_context().push(); db.create_all()" -
Start the application:
gunicorn --bind 0.0.0.0:5000 --reuse-port --reload main:app
-
Open your browser and navigate to
http://localhost:5000
This project is optimized for Replit deployment:
- Fork this repository to your GitHub account
- Import it into Replit
- Add your
GEMINI_API_KEYto Replit Secrets - Click Run - the application will start automatically!
- Click "Choose PDF File" or drag and drop a PDF onto the upload area
- Click "Upload and Process" to begin analysis
- Wait for processing to complete (progress shown in real-time)
- Enjoy your enhanced digital book!
- Text-based PDFs (not scanned images)
- Academic papers, novels, reports, documentation
- Maximum file size: 16MB
- Any length document (optimized for books and long-form content)
- Framework: Flask with SQLAlchemy ORM
- Database: PostgreSQL (production) / SQLite (development)
- PDF Processing: PyMuPDF for text extraction with coordinates
- AI Integration: Google Gemini API for content analysis and image generation
- Styling: Bootstrap with custom dark theme
- Interactions: Progressive enhancement with JavaScript
- Reading Experience: Custom book reader with page navigation
- Responsive: Mobile-first design approach
ProcessingJob: Tracks PDF processing status and progressBookAnalysis: Document-level analysis (genre, themes, mood)BookPage: Page-specific content and analysisMarginalia: AI-generated artwork with positioning data
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Yes |
GEMINI_API_KEY |
Google Gemini API key | No* |
SESSION_SECRET |
Flask session encryption key | Yes |
*Falls back to high-quality mock responses if not provided
- Visit Google AI Studio
- Create a new API key
- Add the key to your environment variables
- Restart the application
The application uses:
- Gemini 2.5 Flash: For content analysis (genre, themes, mood)
- Gemini 2.0 Flash: For marginalia image generation
-
Install development dependencies:
pip install -e . -
Enable debug mode:
export FLASK_ENV=development export FLASK_DEBUG=1
-
Run with hot reload:
flask run --host=0.0.0.0 --port=5000 --debug
ai-enhanced-pdf-reader/
├── app.py # Flask application setup
├── main.py # Application entry point
├── models.py # Database models
├── routes.py # Web routes and API endpoints
├── pdf_processor.py # PDF text extraction logic
├── ai_services.py # AI analysis and image generation
├── templates/ # Jinja2 templates
│ ├── index.html # Upload interface
│ └── book_reader.html # Reading experience
├── static/ # CSS, JavaScript, images
│ ├── css/book-style.css
│ └── js/book-reader.js
└── uploads/ # Uploaded PDF storage
- Database Changes: Update
models.pyand restart - API Endpoints: Add routes in
routes.py - Frontend: Modify templates and static files
- AI Features: Extend
ai_services.py
- Fork this repository on GitHub
- Import into Replit from GitHub
- Add secrets in Replit sidebar:
GEMINI_API_KEYDATABASE_URL(automatically provided)SESSION_SECRET(generate a random string)
- Click Run - automatic deployment!
- Set up PostgreSQL database
- Configure environment variables
- Install dependencies:
pip install -r requirements.txt - Initialize database: Run database setup commands
- Start with Gunicorn:
gunicorn main:app
PDF Upload Fails
- Ensure file is under 16MB
- Check file is a valid PDF with text content
- Verify uploads/ directory exists and is writable
AI Analysis Not Working
- Check
GEMINI_API_KEYis set correctly - Verify internet connection for API calls
- Application falls back to mock responses automatically
Database Errors
- Ensure PostgreSQL is running and accessible
- Check
DATABASE_URLformat:postgresql://user:pass@host:port/db - Run
db.create_all()to initialize tables
Enable debug logging:
import logging
logging.basicConfig(level=logging.DEBUG)Check application logs for detailed error information.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- PyMuPDF for robust PDF text extraction
- Google Gemini for AI-powered content analysis
- Bootstrap for responsive UI components
- Flask ecosystem for web framework
- Replit for seamless deployment platform
For issues and questions:
- Create an issue on GitHub
- Check the troubleshooting section above
- Review the application logs for error details
Built with ❤️ for immersive reading experiences