Skip to content

Monster0506/BookRecommendations

Repository files navigation

Book Swipe: Personalized Book Recommendations

Overview

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.

Features

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

Technology Stack

  • Backend: Python 3.9+, Django 4.x
  • Database: SQLite (development), PostgreSQL (production-ready)
  • Recommendation Engine: Surprise library (SVD algorithm)
  • Data Manipulation: Pandas, NumPy
  • External APIs: requests library for Open Library Covers API and Open Library Books API (for genres).
  • Image Processing: Pillow for favicon generation.
  • Frontend: HTML5, CSS3 (Bootstrap 5), Vanilla JavaScript
  • Dependency Management: uv

Setup Instructions

Follow these steps to get the Book Swipe application up and running on your local machine.

1. Clone the Repository

git clone <repository_url>
cd BookRecommendations

2. Install Dependencies

This project uses uv for dependency management. Ensure you have uv installed. If not, you can install it via pip:

pip install uv

Then, install the project dependencies:

uv sync

3. Download the Book-Crossing Dataset

The 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-dataset

Unzip 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.csv
  • BookRecommendations/data/Ratings.csv
  • BookRecommendations/data/Users.csv

4. Apply Database Migrations

We've added a genre field to the Book model, so new migrations are required.

uv run .\manage.py makemigrations
uv run .\manage.py migrate

5. Load Initial Book Data

This command populates the Book model with data from Books.csv.

uv run .\manage.py load_books

6. Load Initial Rating Data

This command populates the UserInteraction model with initial ratings from Ratings.csv.

uv run .\manage.py load_ratings

7. Create a Django Superuser

This is required to access the Django Admin interface.

uv run .\manage.py createsuperuser

Follow the prompts to create your superuser account.

8. Train the Recommendation Model

This command trains the Surprise recommendation model and saves it to disk. It also outputs RMSE and MAE metrics.

uv run .\manage.py train_model

9. Run the Development Server

uv run .\manage.py runserver

The application will be accessible at http://127.0.0.1:8000/.

Usage Guide

  1. Access the Application: Open your web browser and go to http://127.0.0.1:8000/.
  2. Register/Login: If you are a new user, register for an account. Otherwise, log in with your existing credentials (or the superuser account).
  3. Start Swiping: After logging in, you will be redirected to the book swipe interface (/books/swipe/).
  4. 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.
  5. 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?
  6. Retrain Model (Optional): To update the recommendation model with new user interactions, stop the server and run uv run .\manage.py train_model again.
  7. Benchmark Recommendations (Optional): To evaluate the performance of the recommendation engines, run the benchmarking script:
    uv run benchmark_recommendations.py

Architecture Overview

Book Swipe is a Django web application with a modular structure:

  • users app: Handles user authentication and now provides enhanced user profiles with interaction statistics, similar user discovery, and preferred genre insights.
  • book_catalog app: Manages book metadata, the core book swipe interface, and dynamically fetches book genres from the Open Library API.
  • interactions app: Stores user interactions (likes, dislikes, skips) with books.
  • recommendations_engine app: Contains the Surprise-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.

Key Design Decisions

  • Hybrid Recommendation System: Combines collaborative filtering with content-based (genre) filtering for more relevant and diverse recommendations.
  • Surprise Library: 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.
  • uv for 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.

Future Enhancements

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

License

This project is open-source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors