Book Swipe is an interactive web application inspired by the "Tinder" user experience, designed to help users discover new books through a gamified interface. Users can "swipe" (like or dislike) book recommendations presented one at a time. The core of the recommendation generation is a sophisticated hybrid collaborative filtering engine, now enhanced with genre-awareness, implemented using Python's Surprise library.
- User Authentication: Secure user registration, login, and logout.
- Interactive Book Discovery: "Swipe" interface with "Like", "Dislike", and "Skip" functionality.
- Dynamic Book Covers: Fetches book cover images dynamically from the Open Library Covers API.
- Personalized Recommendations: Utilizes a
Surprise-based collaborative filtering model (SVD) and a graph-like approach, now intelligently re-ranked with user-preferred genres to provide even more tailored book suggestions. - Cold Start Handling: Provides popular books to new users until enough interaction data is collected for personalized recommendations. Even these are now genre-aware, because we care.
- Enhanced User Profiles: Users can view their interaction statistics (liked/disliked book counts), discover similar users based on shared tastes, and see their top preferred genres.
- Dynamic Book Genres: Fetches book genre information dynamically from the Open Library API, enriching book data on the fly.
- Performance Optimization: The recommendation model is now cached in memory after its first load, significantly speeding up subsequent recommendation requests.
- Recommendation Benchmarking: Includes a dedicated script to evaluate the performance of different recommendation strategies using metrics like RMSE, MAE, Precision@K, Recall@K, and F1-score.
- Model Retraining: Includes a Django management command to train and evaluate the recommendation model periodically.
- Responsive Design: Adapts to various screen sizes (desktop, tablet, mobile).
- Favicon: Because every great application deserves a little icon in the browser tab.
- Backend: Python 3.9+, Django 4.x
- Database: SQLite (development), PostgreSQL (production-ready)
- Recommendation Engine:
Surpriselibrary (SVD algorithm) - Data Manipulation:
Pandas,NumPy - External APIs:
requestslibrary for Open Library Covers API and Open Library Books API (for genres). - Image Processing:
Pillowfor favicon generation. - Frontend: HTML5, CSS3 (Bootstrap 5), Vanilla JavaScript
- Dependency Management:
uv
Follow these steps to get the Book Swipe application up and running on your local machine.
git clone <repository_url>
cd BookRecommendationsThis project uses uv for dependency management. Ensure you have uv installed. If not, you can install it via pip:
pip install uvThen, install the project dependencies:
uv syncThe application uses the Book-Crossing dataset for initial book and rating data. Download it using curl:
curl -L -o ~/Downloads/bookcrossing-dataset.zip https://www.kaggle.com/api/v1/datasets/download/somnambwl/bookcrossing-datasetUnzip the downloaded file (bookcrossing-dataset.zip) into a data directory within the project root (BookRecommendations/data/). You should have the following files:
BookRecommendations/data/Books.csvBookRecommendations/data/Ratings.csvBookRecommendations/data/Users.csv
We've added a genre field to the Book model, so new migrations are required.
uv run .\manage.py makemigrations
uv run .\manage.py migrateThis command populates the Book model with data from Books.csv.
uv run .\manage.py load_booksThis command populates the UserInteraction model with initial ratings from Ratings.csv.
uv run .\manage.py load_ratingsThis is required to access the Django Admin interface.
uv run .\manage.py createsuperuserFollow the prompts to create your superuser account.
This command trains the Surprise recommendation model and saves it to disk. It also outputs RMSE and MAE metrics.
uv run .\manage.py train_modeluv run .\manage.py runserverThe application will be accessible at http://127.0.0.1:8000/.
- Access the Application: Open your web browser and go to
http://127.0.0.1:8000/. - Register/Login: If you are a new user, register for an account. Otherwise, log in with your existing credentials (or the superuser account).
- Start Swiping: After logging in, you will be redirected to the book swipe interface (
/books/swipe/). - Interact with Books: Click the "Like", "Dislike", or "Skip" buttons to interact with the displayed books. Your interactions will be used to refine future recommendations.
- Explore Your Profile: Visit your profile page to see your interaction statistics, preferred genres, and discover users with similar tastes. Who knew your reading habits were so revealing?
- Retrain Model (Optional): To update the recommendation model with new user interactions, stop the server and run
uv run .\manage.py train_modelagain. - Benchmark Recommendations (Optional): To evaluate the performance of the recommendation engines, run the benchmarking script:
uv run benchmark_recommendations.py
Book Swipe is a Django web application with a modular structure:
usersapp: Handles user authentication and now provides enhanced user profiles with interaction statistics, similar user discovery, and preferred genre insights.book_catalogapp: Manages book metadata, the core book swipe interface, and dynamically fetches book genres from the Open Library API.interactionsapp: Stores user interactions (likes, dislikes, skips) with books.recommendations_engineapp: Contains theSurprise-based collaborative filtering logic, now featuring genre-aware re-ranking and in-memory model caching for blazing-fast recommendations.
User interactions are stored in the database and periodically used to retrain the recommendation model. Book cover images and genres are fetched on-the-fly from the Open Library APIs.
- Hybrid Recommendation System: Combines collaborative filtering with content-based (genre) filtering for more relevant and diverse recommendations.
SurpriseLibrary: Provides a robust and easy-to-use framework for implementing and evaluating recommendation algorithms.- Cold Start Strategy: New users receive popular book recommendations initially to gather enough interaction data before personalized recommendations can be generated.
- Model Caching: The recommendation model is loaded once and kept in memory, drastically reducing latency for subsequent recommendation requests.
- Dynamic Genre Loading: Fetches genre information on demand, ensuring data freshness and reducing initial database load.
- SQLite for Development: Simple and file-based, suitable for local development. PostgreSQL is recommended for production environments.
uvfor Dependency Management: Ensures fast and reliable dependency resolution and installation.- Dynamic Image Loading: Reduces initial page load time and bandwidth by fetching book covers only when needed.
- Real-time Model Updates: Explore techniques for incremental model updates.
- Advanced User Profiles: Allow users to save liked books, create wishlists.
- Social Features: Enable sharing recommendations or following other users.
- Advanced Frontend: Migrate to a modern JavaScript framework for richer UI/UX.
- Production Deployment: Set up Docker, CI/CD, and cloud hosting.
This project is open-source and available under the MIT License.