Spaces:
Configuration error
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`'s `TfidfVectorizer`. | |
* **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 | |
1. **Clone the repository:** | |
```bash | |
git clone [https://github.com/](https://github.com/)<your_username>/<your_repo_name>.git # Replace with your repo URL | |
cd <your_repo_name> | |
``` | |
2. **Create a virtual environment (recommended):** | |
```bash | |
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) | |
``` | |
3. **Install the dependencies:** | |
```bash | |
pip install -r requirements.txt | |
``` | |
4. **Run the app:** | |
```bash | |
python app.py | |
``` | |
5. **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 | |
1. **Create a Hugging Face account:** If you don't have one, sign up at [huggingface.co](https://huggingface.co). | |
2. **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." | |
3. **Push your code to the Space:** | |
* Clone the newly created Git repository: | |
```bash | |
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: | |
```bash | |
git add . | |
git commit -m "Initial commit" | |
git push origin main | |
``` | |
4. **Wait for the build:** Hugging Face Spaces will automatically build your app. Monitor the build progress on your Space page. | |
5. **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 | |
1. Upload your book data file. | |
2. Enter the title of a book you like. | |
3. The app will recommend similar books. | |
## Contributing | |
Contributions are welcome! Please open an issue or submit a pull request. | |
## License | |
[MIT License](LICENSE) (Or your chosen license) |