Building a Personalized Book Recommender System

Published on 25-08-2025


📚 Overview

This project creates a content-based book recommendation engine that suggests similar books to readers based on their input. The focus was on Flask for the web interface and Python for backend logic.

⚙️ Tech Stack

🛠️ Implementation Steps

  1. Prepared datasets with book titles, authors, images, and ratings
  2. Computed similarity using vectorized representations of books
  3. Stored processed data in popular.pkl, pt.pkl, books.pkl, and similarity_scores.pkl
  4. Created two Flask routes:
    • / → shows popular books
    • /recommend → search UI for user input
  5. On submit, the system fetches top 4 similar books and displays titles, authors, and cover images.

📸 UI Preview

Book Recommender UI 1

Homepage & Search Page

Book Recommender UI 2

Recommendation Results Page

📜 Key Code Snippet

@app.route('/recommend_books', methods=['POST'])
def recommend():
    user_input = request.form.get('user_input').strip().lower()

    index_array = np.where(pt.index.str.lower() == user_input)[0]
    if len(index_array) == 0:
        return render_template('recommend.html', data=[], error="⚠️ Book not found!")

    index = index_array[0]
    similar_items = sorted(list(enumerate(similarity_scores[index])),
                            key=lambda x: x[1], reverse=True)[1:5]

    data = []
    for i in similar_items:
        temp_df = books[books['Book-Title'].str.lower() == pt.index[i[0]].lower()]
        if not temp_df.empty:
            data.append([temp_df['Book-Title'].values[0],
                         temp_df['Book-Author'].values[0],
                         temp_df['Image-URL-M'].values[0]])

    return render_template('recommend.html', data=data)
      

This route processes user input and displays the recommended books.

💡 Lessons Learned

🚀 Conclusion

This Book Recommender is a lightweight Flask application that shows how similarity-based approaches can deliver personalized book suggestions. Future improvements could include collaborative filtering and hybrid recommendations using user ratings.


← Back to Portfolio