Skip to content

A intelligent book recommendation web application built with Flask along with bootstrap and machine learning. This system suggests similar books based on user input and displays the top 50 most popular books from a comprehensive dataset.

Notifications You must be signed in to change notification settings

Code-With-Samuel/book_recommender_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Book Recommender System

A intelligent book recommendation web application built with Flask and machine learning. This system suggests similar books based on user input and displays the top 50 most popular books from a comprehensive dataset.

๐Ÿ“š Overview

The Book Recommender System is designed to help users discover new books they might enjoy based on similarity analysis. It features two main sections:

  1. Home Page: Displays the top 50 most rated and voted books with book covers, titles, authors, vote counts, and ratings
  2. Recommendation Engine: Allows users to search for a book and receive personalized recommendations based on cosine similarity scores

๐ŸŽฏ Features

  • Popular Books Showcase: Browse the top 50 most popular books with detailed information including:

    • Book cover images
    • Book titles
    • Author names
    • Number of votes/ratings
    • Average rating scores
  • Intelligent Recommendations: Search for any book and receive 4 personalized book recommendations based on collaborative filtering using cosine similarity

  • Interactive Web Interface: Clean, user-friendly interface built with Bootstrap with a dark theme and green navigation bar

  • Fast Recommendations: Pre-computed similarity scores for instant book recommendations without model retraining

๐Ÿ—๏ธ Project Structure

book_recommender_system/
โ”œโ”€โ”€ app.py                 # Flask application with routes
โ”œโ”€โ”€ book_recommender.ipynb # Jupyter notebook with model development
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ pyproject.toml        # Project configuration
โ”œโ”€โ”€ Procfile              # Heroku deployment configuration
โ”œโ”€โ”€ README.md             # This file
โ”œโ”€โ”€ model/                # Pre-trained model files
โ”‚   โ”œโ”€โ”€ popular.pkl       # Top 50 popular books dataset
โ”‚   โ”œโ”€โ”€ pt.pkl            # Pivot table for recommendations
โ”‚   โ”œโ”€โ”€ books.pkl         # Complete books dataset
โ”‚   โ””โ”€โ”€ similarity_scores.pkl  # Pre-computed similarity matrix
โ””โ”€โ”€ templates/            # HTML templates
    โ”œโ”€โ”€ index.html        # Home page with top books
    โ””โ”€โ”€ recommend.html    # Recommendation page

๐Ÿ› ๏ธ Technology Stack

  • Backend: Flask
  • Data Processing: Pandas, NumPy
  • Machine Learning: Cosine Similarity (Collaborative Filtering)
  • Frontend: Bootstrap 3.7
  • Data Serialization: Pickle

๐Ÿ“‹ Requirements

Flask
NumPy
Pandas

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.7 or higher
  • pip (Python package manager)

Installation

  1. Clone or download the project:
cd book_recommender_system
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the Flask application:
python app.py
  1. Open your browser and navigate to:
http://127.0.0.1:5000/

๐Ÿ’ป Usage

Home Page

Navigate to the home page to view the Top 50 Books dashboard:

Top 50 Books - Homepage

The homepage displays:

  • Book cover images in a card layout
  • Book titles and authors
  • Number of votes received
  • Average rating scores
  • Easy navigation to the recommendation engine

Recommendation Page

Click on "Recommend" in the navigation bar to access the recommendation engine:

Recommend Books - Search Interface

How to use:

  1. Enter a book title in the search box
  2. Click the "Submit" button
  3. The system displays 4 recommended books similar to your search
  4. Recommendations are based on book similarity and user ratings

๐Ÿค– How It Works

Data Processing Pipeline

  1. Data Collection: The system uses a dataset containing books with their titles, authors, and user ratings
  2. Popular Books Selection: Identifies the top 50 most voted and rated books for homepage display
  3. Pivot Table Creation: Creates a user-book rating matrix for similarity computation
  4. Similarity Calculation: Computes cosine similarity scores between all books
  5. Recommendations: Returns the 4 most similar books (excluding the query book itself)

Algorithm

The recommendation engine uses Cosine Similarity with Collaborative Filtering:

  • Cosine Similarity: Measures the angle between rating vectors, ignoring magnitude
  • Collaborative Filtering: Based on the assumption that users who rated books similarly will enjoy the same books
  • Pre-computed Scores: Similarity matrices are pre-calculated for instant recommendations

๐Ÿ“Š Model Files

The model/ directory contains pre-trained pickle files:

File Purpose
popular.pkl DataFrame of top 50 popular books
pt.pkl Pivot table (books ร— users) for similarity computation
books.pkl Complete books dataset with metadata
similarity_scores.pkl Pre-computed cosine similarity matrix

๐Ÿ“ API Routes

GET /

  • Description: Home page showing top 50 books
  • Response: HTML page with book gallery

GET /recommend

  • Description: Recommendation search interface
  • Response: HTML form for book search

POST /recommend_books

  • Description: Get recommendations for a book
  • Parameters:
    • user_input (string): Book title to search
  • Response: HTML page with 4 recommended books

๐ŸŽจ Frontend Features

  • Responsive Design: Works on desktop and mobile devices (Bootstrap grid)
  • Dark Theme: Black background with white text for better readability
  • Color Scheme: Green navigation bar (#00a65a) and orange submit button
  • Card Layout: Books displayed in responsive card components
  • Image Integration: Book cover images loaded from URLs

๐Ÿ“ˆ Performance

  • Instant Recommendations: Pre-computed similarity scores eliminate model inference delays
  • Scalable Architecture: Pickle serialization allows quick loading of large datasets
  • Lightweight: No heavy ML libraries required at runtime
  • Efficient Search: Direct index lookup for user queries
  • Local-First: Optimized for local development and usage

๐Ÿ”„ Data Flow

User Input (Book Title)
    โ†“
Index Lookup in Pivot Table
    โ†“
Retrieve Pre-computed Similarity Scores
    โ†“
Sort by Similarity (descending)
    โ†“
Select Top 4 Recommendations
    โ†“
Fetch Book Details (title, author, image)
    โ†“
Display to User

๐Ÿ› Troubleshooting

"Book not found" error

  • Ensure the book title exists in the dataset
  • Try searching with partial titles
  • Check case sensitivity (though the system should handle this)

Missing model files

  • Ensure all .pkl files are present in the model/ directory
  • Run the Jupyter notebook to regenerate model files if needed

Port already in use

  • Change the port in app.py:
app.run(debug=True, port=5001)

๐Ÿ“š Dataset Information

The project uses a comprehensive book dataset containing:

  • Thousands of unique books
  • User ratings and votes
  • Book metadata (title, author, ISBN)
  • Book cover images

๐Ÿ”ฎ Future Enhancements

  • User authentication and personalized recommendations
  • Advanced filtering (genre, publication year, price range)
  • User ratings and review system
  • Content-based filtering using book descriptions
  • Hybrid recommendation system combining multiple approaches
  • Search autocomplete and suggestions
  • Mobile app version
  • Integration with library APIs

๐Ÿ“„ License

This project is open source and available for educational and commercial use.

๐Ÿ‘ค Author

Created as a book recommendation system for discovering similar books based on user preferences.

๐Ÿ“ž Support

For issues or feature requests, please create an issue in the project repository.


Last Updated: January 2026

About

A intelligent book recommendation web application built with Flask along with bootstrap and machine learning. This system suggests similar books based on user input and displays the top 50 most popular books from a comprehensive dataset.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published