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.
| 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 |
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
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 |
git clone https://github.com/Adityaz23/books-recommendation.git
cd books-recommendationUsing a virtual environment keeps your dependencies isolated and avoids conflicts with other Python projects.
# Create the virtual environment
python3 -m venv venv
# Activate it
source venv/bin/activate:: Create the virtual environment
python -m venv venv
:: Activate it
venv\Scripts\activate# 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.
pip install -r requirements.txtThis 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 runningpip install -r requirements.txt.
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 > .envThen open .env and add the following:
GROQ_API_KEY=your_groq_api_key_here
Or any other LLM API which you want to use.- Go to https://console.groq.com
- Sign up or log in with your account
- Navigate to API Keys in the left sidebar
- Click Create API Key
- Copy the key and paste it into your
.envfile
โน๏ธ The
GROQ_API_KEYis 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.
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):
- Open
app.pyand 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"
)- Comment out the production loading block below it:
# db_books = Chroma(
# persist_directory="chroma_db",
# embedding_function=embedding_model
# )- Run
app.pyonce โ it will create the index and save it. Then reverse the comments back for normal usage.
python app.pyThe Gradio app will launch and be accessible at:
http://localhost:7860
Or on your local network at:
http://0.0.0.0:7860
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"
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
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 |
| 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" |
Contributions are welcome! To contribute:
- Fork the repo
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m 'Add your feature' - Push to the branch:
git push origin feature/your-feature - Open a Pull Request
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!
