AI-driven application that recommends books based on emotions detected in user input and whether the user prefers fiction or non-fiction. This project leverages both OpenAI and Hugging Face APIs to perform text classification and zero-shot classification, respectively.
The Semantic Book Recommender uses Natural Language Processing (NLP) techniques to analyze user input and suggest books. It relies on:
- Emotion Detection: Determines the emotional tone (e.g., joy, sadness) of the user’s input.
- Genre Classification: Uses zero-shot classification to categorize the user's query into "Fiction" or "Nonfiction."
By combining these insights, the application surfaces a curated list of book recommendations.
- Emotion Analysis: Powered by
j-hartmann/emotion-english-distilroberta-basefor robust emotion classification. - Zero-Shot Classification: Uses
facebook/bart-large-mnlito distinguish between Fiction and Nonfiction. - Interactive Dashboard: Built with Gradio for a user-friendly interface.
- CSV-based Book Data: Pre-processed and stored in
books_with_emotions.csvandbooks_with_categories.csv.
- Clone the Repository
git clone https://github.com/YourUsername/Book-Recommender.git cd Book-Recommender/book_recommender - Create a Virtual Environment (Optional but Recommended)
python3 -m venv venv source venv/bin/activate # On macOS/Linux # or venv\Scripts\activate # On Windows
- Install Dependencies
pip install -r requirements.txt
- Set Up API Keys
- OpenAI: Create a
.envfile or export your API key as an environment variable:
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"- Hugging Face: If required, configure your token similarly:
HUGGINGFACEHUB_API_TOKEN="YOUR_HF_API_KEY" - OpenAI: Create a
- Run the Gradio Dashboard
python3 gradio-dashboard.py
- Access the Application
- Copy the URL printed in the console (something like
http://127.0.0.1:7860). - Open it in your browser.
- Copy the URL printed in the console (something like
- Interact with the Dashboard
- Provide a short description of a book you’re looking for, or a phrase that captures your mood.
- Choose optional categories or let the model handle them automatically.
- View the recommendations and explore the listed books.
book_recommender/
├── books_cleaned.csv
├── books_with_categories.csv
├── books_with_emotions.csv
├── cover-not-found.jpg
├── data-exploration.ipynb
├── gradio-dashboard.py
├── requirements.txt
├── sentiment-analysis.ipynb
├── tagged_description.txt
├── text-classification.ipynb
├── vector-search.ipynb
└── ...gradio-dashboard.py:Main file to launch the Gradio interface.books_with_emotions.csvandbooks_with_categories.csv:Data files used for recommendations..ipynbnotebook: Exploratory notebooks showcasing data cleaning, text classification, sentiment analysis, and vector search.
- Emotion Classification
from transformers import pipeline classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") # Analyzes the user's text and infers the dominant emotion.
- Zero-Shot Classification
from transformers import pipeline fiction_categories = ["Fiction", "Nonfiction"] pipe = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") # Classifies user input to decide whether they want Fiction or Nonfiction.
- Integration with OpenAI
- OpenAI is used for any language model queries or text embeddings (depending on your configuration with
langchain).
- OpenAI is used for any language model queries or text embeddings (depending on your configuration with
- Gradio Frontend
- Provides a web interface for user input and displays the recommended books.
- Data
- The CSV files contain pre-labeled or pre-processed metadata about books (title, author, categories, etc.).
- Email: kennygarcia15@yahoo.com
- LinkedIn: linkedin.com/in/kennygarcia15 Feel free to reach out if you have questions, suggestions, or feedback!
Thank you for checking out the Semantic Book Recommender. Enjoy exploring new reads tailored to your mood and preferences!
