Devam / upload_to_hf.py
Devam0's picture
corrections
355774b
Raw
History Blame Contribute Delete
3.15 kB
#!/usr/bin/env python3
"""
Helper script to upload Devam Jersey Server to Hugging Face Spaces
"""
import os
import subprocess
import sys
def run_command(command, description):
"""Run a command and handle errors"""
print(f"πŸ”„ {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"βœ… {description} completed successfully")
return result.stdout
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed:")
print(f"Error: {e.stderr}")
return None
def check_git_status():
"""Check if we're in a git repository and if it's clean"""
if not os.path.exists('.git'):
print("❌ Not in a git repository. Please initialize git first:")
print(" git init")
print(" git add .")
print(" git commit -m 'Initial commit'")
return False
# Check if there are uncommitted changes
result = subprocess.run("git status --porcelain", shell=True, capture_output=True, text=True)
if result.stdout.strip():
print("⚠️ There are uncommitted changes. Please commit them first:")
print(" git add .")
print(" git commit -m 'Update before HF upload'")
return False
return True
def main():
print("πŸš€ Devam Jersey Server - Hugging Face Upload Helper")
print("=" * 50)
# Check prerequisites
if not check_git_status():
return
# Check if huggingface_hub is installed
try:
import huggingface_hub
print("βœ… huggingface_hub is installed")
except ImportError:
print("❌ huggingface_hub not found. Installing...")
run_command("pip install huggingface_hub", "Installing huggingface_hub")
print("\nπŸ“‹ Next steps to upload to Hugging Face:")
print("1. Go to https://huggingface.co/spaces")
print("2. Click 'Create new Space'")
print("3. Choose 'Docker' as the SDK")
print("4. Set Space name (e.g., 'devam-jersey-server')")
print("5. Set visibility (Public or Private)")
print("6. Click 'Create Space'")
print("\n7. Clone the created space:")
print(" git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server")
print(" cd devam-jersey-server")
print("\n8. Copy your project files to the cloned directory")
print("9. Push to Hugging Face:")
print(" git add .")
print(" git commit -m 'Initial upload'")
print(" git push")
print("\nπŸ”§ Alternative: Use huggingface_hub CLI")
print(" huggingface-cli repo create devam-jersey-server --type space --space-sdk docker")
print(" cd devam-jersey-server")
print(" # Copy files and push as above")
print("\nπŸ“ Important notes:")
print("- Make sure your model files are not too large (>5GB total)")
print("- The space will automatically build and deploy your Docker container")
print("- Check the 'Settings' tab in your space for environment variables if needed")
print("- Monitor the build logs in the 'Logs' tab")
if __name__ == "__main__":
main()