Spaces:
Configuration error
title: Book Recommender 01 # Your Space's title emoji: 📊 # An emoji for your Space (optional) colorFrom: red # Color for the Space's theme (optional) colorTo: gray # Color for the Space's theme (optional) sdk: gradio # Important: Specifies the Gradio SDK app_file: app.py # The name of your main Python file (case-sensitive!)
sdk_version: 5.14.0 # Remove this line unless you have a VERY specific reason to pin an older version
Book Recommender App
This is a book recommendation app built using Python, scikit-learn, and Gradio. It uses TF-IDF vectorization and cosine similarity to recommend books based on their summaries.
Functionality
- File Upload and Processing: Users can upload CSV or Excel files containing book data (title and summary). This uses the
pandas
library. - Data Preprocessing: Handles missing values and removes duplicates using
pandas
. - TF-IDF Vectorization: Converts book summaries to numerical vectors using
scikit-learn
'sTfidfVectorizer
. - Similarity Calculation: Calculates cosine similarity between TF-IDF vectors using
scikit-learn
. - Book Recommendation: Recommends similar books based on a user-provided title.
- User Interface: Provides an interactive interface using
gradio
.
Dependencies
- pandas: For data loading, manipulation, and preprocessing (CSV and Excel file handling).
- scikit-learn: For TF-IDF vectorization and cosine similarity calculation.
- gradio: For creating the interactive user interface.
How to Run Locally
Clone the repository:
git clone [https://github.com/](https://github.com/)<your_username>/<your_repo_name>.git # Replace with your repo URL cd <your_repo_name>
Create a virtual environment (recommended):
python3 -m venv .venv # Create a virtual environment (Linux/macOS) source .venv/bin/activate # Activate the environment (Linux/macOS) .venv\Scripts\activate # Activate the environment (Windows)
Install the dependencies:
pip install -r requirements.txt
Run the app:
python app.py
Open the app in your browser: Gradio will provide a URL (usually
http://127.0.0.1:7860/
).
How to Deploy on Hugging Face Spaces
Create a Hugging Face account: If you don't have one, sign up at huggingface.co.
Create a new Space:
- Click on "New Space."
- Give your Space a name.
- Select the "Gradio" SDK.
- Choose a hardware and storage upgrade if needed.
- Select a license (e.g., MIT).
- Click "Create Space."
Push your code to the Space:
Clone the newly created Git repository:
git clone [https://huggingface.co/spaces/](https://huggingface.co/spaces/)<your_username>/<your_space_name> cd <your_space_name>
Copy all the necessary files (
app.py
,requirements.txt
, your data file,README.md
,config.yaml
) into the cloned repository.Commit and push your changes:
git add . git commit -m "Initial commit" git push origin main
Wait for the build: Hugging Face Spaces will automatically build your app. Monitor the build progress on your Space page.
Access your deployed app: Once the build is successful, your app will be live at a URL provided by Hugging Face.
Data File
The app requires a CSV or Excel file containing book data, including at least the title
and summary
columns. The file should be named (e.g., books.csv
) and placed in the same directory as app.py
. The path to the file is specified in the load_data
method of the BookRecommender
class within app.py
.
Example Usage
- Upload your book data file.
- Enter the title of a book you like.
- The app will recommend similar books.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
MIT License (Or your chosen license)