|
|
|
""" |
|
Upload the B2B Ecommerce NER model to Hugging Face Hub |
|
""" |
|
|
|
from huggingface_hub import HfApi, create_repo |
|
import os |
|
from pathlib import Path |
|
|
|
|
|
def upload_to_huggingface(repo_name: str, token: str = None): |
|
""" |
|
Upload the model to Hugging Face Hub |
|
|
|
Args: |
|
repo_name: Name of the repository (e.g., "username/b2b-ecommerce-ner") |
|
token: Hugging Face token (or set HF_TOKEN environment variable) |
|
""" |
|
|
|
if token is None: |
|
token = os.getenv("HF_TOKEN") |
|
if not token: |
|
print("Please provide a Hugging Face token or set HF_TOKEN environment variable") |
|
return False |
|
|
|
api = HfApi() |
|
|
|
try: |
|
|
|
print(f"Creating repository: {repo_name}") |
|
create_repo(repo_name, token=token, exist_ok=True) |
|
|
|
|
|
model_dir = Path(__file__).parent |
|
|
|
print("Uploading files...") |
|
api.upload_folder( |
|
folder_path=model_dir, |
|
repo_id=repo_name, |
|
token=token, |
|
repo_type="model" |
|
) |
|
|
|
print(f"✅ Model uploaded successfully to: https://huggingface.co/{repo_name}") |
|
return True |
|
|
|
except Exception as e: |
|
print(f"❌ Upload failed: {e}") |
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
import sys |
|
|
|
if len(sys.argv) != 2: |
|
print("Usage: python upload.py <repo_name>") |
|
print("Example: python upload.py username/b2b-ecommerce-ner") |
|
sys.exit(1) |
|
|
|
repo_name = sys.argv[1] |
|
success = upload_to_huggingface(repo_name) |
|
|
|
if success: |
|
print("\nYour model is now available on Hugging Face!") |
|
print(f"You can use it with: B2BEcommerceNER.from_pretrained('{repo_name}')") |
|
else: |
|
print("\nUpload failed. Please check your token and try again.") |
|
|