Spaces:
Sleeping
Sleeping
metadata
license: mit
title: Product Categorization Demo
sdk: streamlit
emoji: π
colorFrom: purple
colorTo: yellow
Product Categorization App - Streamlit Demo
This is a Streamlit application for categorizing products based on their similarity to ingredients or predefined categories using AI embeddings (e.g., Voyage AI) and optional reranking (Voyage AI, OpenAI).
Quick Start
- Clone the repository:
git clone <repository_url> cd <repository_directory>
- Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
- Prepare Embeddings: Ensure your embedding files (
ingredient_embeddings_voyageai.pkl
,category_embeddings.pickle
, etc.) are present in thedata/
directory. - Configure API Keys:
- Copy the
.env.example
file (if it exists) or create a new file named.env
. - Add your API keys to the
.env
file:VOYAGE_API_KEY="YOUR_VOYAGE_API_KEY_HERE" OPENAI_API_KEY="YOUR_OPENAI_API_KEY_HERE" # Add other keys like CHICORY if needed
- Copy the
- Run the application:
Alternatively, if you have configured thestreamlit run app.py
./run_app.sh
script:./run_app.sh
- The application will open in your default web browser.
Features
- Multiple Matching Methods:
- Ingredient Embeddings
- Category Embeddings
- Voyage AI Reranking (Ingredients/Categories)
- OpenAI Reranking (Ingredients/Categories)
- Comparison View across methods
- Text Input: Enter product names one per line.
- Description Expansion: Optionally use OpenAI to expand product descriptions before matching.
- Adjustable Parameters: Control Top-N results, confidence thresholds, etc. for different methods.
- Example Loading: Quickly load sample product names.
Hosting on Hugging Face Spaces
- Create a free account on Hugging Face.
- Go to Hugging Face Spaces.
- Click "Create a new Space".
- Select "Streamlit" as the SDK.
- Choose a repository type (usually Git).
- Upload all project files (including the
data
directory with embeddings) to the space repository. - Important: Add your API keys (
VOYAGE_API_KEY
,OPENAI_API_KEY
, etc.) as Secrets in your Hugging Face Space settings. Do not commit the.env
file directly. - Your app should build and deploy automatically.
Files Included
app.py
: The main Streamlit application entry point.ui.py
: Defines the Streamlit UI layout and components.*.py
(various): Backend logic for embeddings, matching, API calls, formatting.requirements.txt
: Required Python packages..env
: File to store API keys (add your keys here, do not commit).run_app.sh
: Example script to run the app locally.data/
: Directory containing embedding files.
Requirements
- Python 3.8+
- API keys for Voyage AI and/or OpenAI (stored in
.env
). - Internet connection for API calls.