Skip to content

Latest commit

ย 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š Semantic Book Recommender

Discover your next favorite book using AI-powered semantic search, emotional tone filtering, and category-based recommendations โ€” built with LangChain, ChromaDB, HuggingFace Embeddings, and Gradio.

Python Gradio LangChain ChromaDB License: MIT

Demo Screenshot


โœจ Features

Feature Description
๐Ÿ” Semantic Search Describe the kind of book you want in plain English โ€” the AI finds the closest matches
๐Ÿท๏ธ Category Filtering Filter results by genre/category (Fiction, Science, History, etc.)
๐ŸŽญ Emotional Tone Filtering Narrow results by mood โ€” Happy, Sad, Suspenseful, Angry, or Surprising
๐Ÿ“– Google Books Links Direct preview links via ISBN for each recommendation
๐Ÿ›’ Amazon Search Links One-click Amazon search for every recommended book
๐Ÿ–ผ๏ธ Book Cover Thumbnails High-resolution cover art for every result
โšก Pre-built Vector DB ChromaDB index is pre-computed and ships with the repo for instant startup

๐Ÿ—‚๏ธ Project Structure

books-recommendation/
โ”œโ”€โ”€ app.py                        # Main Gradio application
โ”œโ”€โ”€ requirements.txt              # Python dependencies
โ”œโ”€โ”€ books_cleaned.csv             # Raw cleaned book dataset
โ”œโ”€โ”€ books_with_categories.csv     # Dataset with category labels
โ”œโ”€โ”€ books_with_emotions.csv       # Dataset with emotion scores (used at runtime)
โ”œโ”€โ”€ tagged_description.txt        # Tagged book descriptions for vector indexing
โ”œโ”€โ”€ chroma_db/                    # Pre-built ChromaDB vector store
โ”‚   โ”œโ”€โ”€ chroma.sqlite3
โ”‚   โ””โ”€โ”€ e24a8b8f-.../             # Embedding shard
โ”œโ”€โ”€ cover-not-found.png           # Fallback cover image
โ”œโ”€โ”€ data-exploration.ipynb        # EDA notebook
โ”œโ”€โ”€ sentiment-analysis.ipynb      # Emotion scoring notebook
โ”œโ”€โ”€ text-classification.ipynb     # Category classification notebook
โ””โ”€โ”€ vector-search.ipynb           # Vector DB creation notebook

๐Ÿš€ Local Setup Guide

Prerequisites

Make sure you have the following installed before starting:

Tool Version Link
Python 3.10 or higher python.org
pip Latest Comes with Python
Git Any git-scm.com

Step 1 โ€” Clone the Repository

git clone https://github.com/Adityaz23/books-recommendation.git
cd books-recommendation

Step 2 โ€” Create a Virtual Environment

Using a virtual environment keeps your dependencies isolated and avoids conflicts with other Python projects.

๐Ÿง macOS / Linux

# Create the virtual environment
python3 -m venv venv

# Activate it
source venv/bin/activate

๐ŸชŸ Windows (Command Prompt)

:: Create the virtual environment
python -m venv venv

:: Activate it
venv\Scripts\activate

๐ŸชŸ Windows (PowerShell)

# Create the virtual environment
python -m venv venv

# Activate it
.\venv\Scripts\Activate.ps1

โœ… You'll know it's active when you see (venv) at the start of your terminal prompt.


Step 3 โ€” Install Dependencies

pip install -r requirements.txt

This installs all required packages:

Package Purpose
pandas, numpy Data loading and manipulation
torch PyTorch backend for embeddings
gradio Web UI framework
python-dotenv Load environment variables from .env
langchain + extensions RAG pipeline and document handling
langchain-chroma ChromaDB integration
langchain-huggingface HuggingFace embeddings
sentence-transformers all-MiniLM-L6-v2 embedding model
chromadb Local vector database

โš ๏ธ PyTorch Note: If you want GPU acceleration or are on a specific OS, install PyTorch separately first from pytorch.org before running pip install -r requirements.txt.


Step 4 โ€” Set Up Environment Variables

The app uses a .env file to load your API key securely. Create one in the root of the project:

# In the project root directory
touch .env        # macOS/Linux
# OR on Windows:
type nul > .env

Then open .env and add the following:

GROQ_API_KEY=your_groq_api_key_here
Or any other LLM API which you want to use.

๐Ÿ”‘ How to Get a Groq API Key

  1. Go to https://console.groq.com
  2. Sign up or log in with your account
  3. Navigate to API Keys in the left sidebar
  4. Click Create API Key
  5. Copy the key and paste it into your .env file

โ„น๏ธ The GROQ_API_KEY is loaded by the app but the core semantic search runs entirely via HuggingFace embeddings + ChromaDB locally โ€” so the app will still work for recommendations even without the Groq key. The key is used for any future LLM-powered features.


Step 5 โ€” (Optional) Rebuild the Vector Database

The repo ships with a pre-built ChromaDB index in the chroma_db/ folder. You can use it directly and skip this step.

If you want to rebuild it from scratch (e.g., after modifying tagged_description.txt):

  1. Open app.py and uncomment this block:
# Run this ONCE to build and save the vector database
db_books = Chroma.from_documents(
    documents,
    embedding=embedding_model,
    persist_directory="chroma_db"
)
  1. Comment out the production loading block below it:
# db_books = Chroma(
#     persist_directory="chroma_db",
#     embedding_function=embedding_model
# )
  1. Run app.py once โ€” it will create the index and save it. Then reverse the comments back for normal usage.

Step 6 โ€” Run the Application

python app.py

The Gradio app will launch and be accessible at:

http://localhost:7860

Or on your local network at:

http://0.0.0.0:7860

๐ŸŽฎ How to Use

Once the app is running:

Step Action
1๏ธโƒฃ Type a description of the kind of book you're looking for in the text box
2๏ธโƒฃ (Optional) Select a Category from the dropdown to filter by genre
3๏ธโƒฃ (Optional) Select an Emotional Tone โ€” Happy, Sad, Suspenseful, Angry, or Surprising
4๏ธโƒฃ Click ๐Ÿ” Find Recommendations
5๏ธโƒฃ Browse the book cards โ€” click ๐Ÿ“– Read Preview or ๐Ÿ›’ Buy Book on any result

Example queries to try:

  • "A mystery thriller set in Victorian London"
  • "Uplifting stories about human resilience and hope"
  • "Dark fantasy with complex world-building and magic systems"
  • "A coming-of-age story about loss and identity"

๐Ÿง  How It Works

User Query
    โ”‚
    โ–ผ
HuggingFace Embeddings          โ† sentence-transformers/all-MiniLM-L6-v2
(all-MiniLM-L6-v2)
    โ”‚
    โ–ผ
ChromaDB Vector Search          โ† Top 50 semantically similar books
    โ”‚
    โ–ผ
Category Filter                 โ† Optional genre filter
    โ”‚
    โ–ผ
Emotion Score Re-ranking        โ† Sort by joy / sadness / fear / surprise / anger
    โ”‚
    โ–ผ
Top 16 Results โ†’ Gradio UI      โ† Book cards with cover, description & links

๐Ÿ““ Notebooks

The notebooks/ files walk through the full data pipeline:

Notebook Description
data-exploration.ipynb EDA of the raw book dataset
text-classification.ipynb Classifying books into simplified categories
sentiment-analysis.ipynb Scoring books by emotional tone using NLP
vector-search.ipynb Building and querying the ChromaDB vector index

๐Ÿ› ๏ธ Troubleshooting

Problem Fix
ModuleNotFoundError Make sure your venv is active and you've run pip install -r requirements.txt
No API Key found printed on startup Check your .env file exists in the root folder and has GROQ_API_KEY=...
Port 7860 already in use Change server_port=7860 in app.py to any free port
Slow first startup The HuggingFace embedding model downloads on first use โ€” this is normal
Empty recommendations Try a broader query or set Category and Tone both to "All"

๐Ÿค Contributing

Contributions are welcome! To contribute:

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'Add your feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.


Made with โค๏ธ by Adityaz23

โญ Star this repo if you found it useful!

About

This is the book recommendation system

Resources

Stars

16 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages