Text Classification
Transformers
Safetensors
English
distilbert
shopping
deals
classification
e-commerce
recommendation
text-embeddings-inference
Instructions to use selvaonline/shopping-assistant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use selvaonline/shopping-assistant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="selvaonline/shopping-assistant")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("selvaonline/shopping-assistant") model = AutoModelForSequenceClassification.from_pretrained("selvaonline/shopping-assistant", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download deploy_example.py from selvaonline/shopping-assistant: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/selvaonline/shopping-assistant/resolve/main/deploy_example.py
- Command line
-
hf download hf://selvaonline/shopping-assistant/deploy_example.py
-
curl -L -o deploy_example.py https://huggingface.co/selvaonline/shopping-assistant/resolve/main/deploy_example.py
2.79 kB
| #!/usr/bin/env python3 | |
| """ | |
| Example script for deploying the Shopping Assistant model to Hugging Face Hub | |
| """ | |
| import os | |
| import argparse | |
| import subprocess | |
| import sys | |
| def check_requirements(): | |
| """ | |
| Check if the required packages are installed | |
| """ | |
| try: | |
| import huggingface_hub | |
| import transformers | |
| return True | |
| except ImportError as e: | |
| print(f"Error: {e}") | |
| print("Please install the required packages:") | |
| print("pip install huggingface_hub transformers") | |
| return False | |
| def deploy_model(): | |
| """ | |
| Deploy the model to Hugging Face Hub | |
| """ | |
| parser = argparse.ArgumentParser(description="Deploy the Shopping Assistant model to Hugging Face Hub") | |
| parser.add_argument("--repo-name", type=str, required=True, help="Hugging Face Hub repository name (e.g., username/model-name)") | |
| parser.add_argument("--token", type=str, help="Hugging Face API token") | |
| parser.add_argument("--private", action="store_true", help="Make the repository private") | |
| args = parser.parse_args() | |
| # Check if the deploy_to_huggingface.py script exists | |
| script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "deploy_to_huggingface.py") | |
| if not os.path.exists(script_path): | |
| print(f"Error: deploy_to_huggingface.py not found at {script_path}") | |
| print("Please make sure the script exists in the project directory") | |
| return False | |
| # Build the command | |
| cmd = [sys.executable, script_path, "--repo-name", args.repo_name, "--create-inference"] | |
| if args.token: | |
| cmd.extend(["--token", args.token]) | |
| if args.private: | |
| cmd.append("--private") | |
| # Execute the command | |
| print(f"Deploying model to {args.repo_name}...") | |
| try: | |
| subprocess.run(cmd, check=True) | |
| print("\nDeployment successful!") | |
| print(f"You can access your model at: https://huggingface.co/{args.repo_name}") | |
| print("\nTo use the model for inference:") | |
| print(f"1. Visit https://huggingface.co/{args.repo_name}") | |
| print("2. Use the inference widget on the model page") | |
| print("3. Or use the API with the following code:") | |
| print(f""" | |
| import requests | |
| API_URL = "https://api-inference.huggingface.co/models/{args.repo_name}" | |
| headers = {{"Authorization": "Bearer YOUR_API_TOKEN"}} | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response.json() | |
| output = query({{ | |
| "inputs": "I'm looking for headphones" | |
| }}) | |
| print(output) | |
| """) | |
| return True | |
| except subprocess.CalledProcessError as e: | |
| print(f"Error deploying model: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| if check_requirements(): | |
| deploy_model() | |