dragonllm-finance-models / deploy_to_hf.py
jeanbaptdzd's picture
feat: Clean deployment to HuggingFace Space with model config test endpoint
8c0b652
#!/usr/bin/env python3
"""
Deploy specific files to HuggingFace Space using the API.
This avoids git history issues with exposed tokens.
"""
import os
from dotenv import load_dotenv
from huggingface_hub import HfApi, upload_file
# Load environment variables
load_dotenv()
def deploy_to_hf_space():
"""Upload essential files to HuggingFace Space."""
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
print("❌ HF_TOKEN not found in environment variables")
return False
space_id = "jeanbaptdzd/linguacustodia-financial-api"
# Initialize HF API
api = HfApi()
# Files to upload
files_to_upload = [
"app.py",
"app_config.py",
"Dockerfile",
"requirements.txt",
"docs/README_HF_SPACE.md"
]
print(f"πŸš€ Deploying to HuggingFace Space: {space_id}")
print("=" * 50)
for file_path in files_to_upload:
try:
print(f"πŸ“€ Uploading {file_path}...")
api.upload_file(
path_or_fileobj=file_path,
path_in_repo=file_path,
repo_id=space_id,
repo_type="space",
token=hf_token
)
print(f"βœ… {file_path} uploaded successfully")
except Exception as e:
print(f"❌ Failed to upload {file_path}: {e}")
return False
print("\n" + "=" * 50)
print("βœ… All files uploaded successfully!")
print(f"🌐 Space URL: https://huggingface.co/spaces/{space_id}")
print("⏳ The Space will rebuild automatically")
return True
if __name__ == "__main__":
deploy_to_hf_space()