An AI-powered book recommendation system that uses semantic search and emotion analysis to provide personalized book suggestions based on natural language descriptions.
- Semantic Search: Find books based on natural language descriptions rather than simple keyword matching
- Emotion-Based Filtering: Filter recommendations by emotional tone (Happy, Surprising, Angry, Suspenseful, Sad)
- Category Filtering: Filter books by genre categories (Fiction, Nonfiction, Children's Fiction, Children's Nonfiction)
- Interactive Web Interface: User-friendly Gradio dashboard for exploring recommendations
- Visual Gallery: Display book covers with titles, authors, and descriptions
The system consists of several components:
- Vector Search Engine (
vector-search.py): Creates embeddings from book descriptions using OpenAI embeddings and stores them in a Chroma vector database for semantic similarity search - Text Classification (
text-classification.py): Categorizes books using zero-shot classification with Facebook's BART model - Sentiment Analysis (
sentiment-analysis.py): Analyzes emotional content of book descriptions using DistilRoBERTa emotion classifier - Gradio Dashboard (
gradio-dashboard.py): Provides an interactive web interface for searching and browsing recommendations
- Clone the repository:
git clone https://github.com/tarek-gritli/semantic-book-recommender.git
cd semantic-book-recommender- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
Create a
.envfile in the project root and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
The system expects the following CSV files:
books.csv: Original book datasetbooks_cleaned.csv: Preprocessed book data with descriptions obtained through the Semantic Book Recommender Kaggle notebookbooks_with_categories.csv: Books with category classificationsbooks_with_emotions.csv: Books with emotion analysis scores
Launch the Gradio dashboard:
python gradio-dashboard.pyThe interface will open in your browser where you can:
- Enter a natural language description of the type of book you're looking for
- Select a category filter (optional)
- Select an emotional tone filter (optional)
- View recommended books in a visual gallery
If you need to process new book data:
- Prepare vector embeddings:
python vector-search.py- Classify book categories:
python text-classification.py- Analyze emotional content:
python sentiment-analysis.py- Language Models:
- OpenAI Embeddings for semantic search
- Facebook BART for zero-shot classification
- DistilRoBERTa for emotion analysis
- Vector Database: Chroma for efficient similarity search
- ML Framework: Transformers, LangChain
- Web Interface: Gradio
- Data Processing: Pandas, NumPy
semantic-book-recommender/
├── gradio-dashboard.py # Web interface
├── vector-search.py # Embedding generation and search
├── text-classification.py # Category classification
├── sentiment-analysis.py # Emotion analysis
├── requirements.txt # Python dependencies
├── books*.csv # Book datasets
├── tagged_descriptions.txt # Processed descriptions for embedding
└── .env # Environment variables (not in repo)
Key dependencies include:
langchainandlangchain-chromafor vector searchtransformersfor NLP modelsgradiofor web interfacepandasfor data processingopenaifor embeddings
See requirements.txt for complete list.