Spaces:
Sleeping
Sleeping
| # Script to deploy the application to Hugging Face Spaces | |
| set -e | |
| # Check if huggingface_hub is installed | |
| if ! pip show huggingface_hub > /dev/null 2>&1; then | |
| echo "Installing huggingface_hub..." | |
| pip install huggingface_hub | |
| fi | |
| # Check if git is installed | |
| if ! command -v git &> /dev/null; then | |
| echo "Error: git is not installed. Please install git and try again." | |
| exit 1 | |
| fi | |
| # Get Hugging Face username | |
| read -p "Enter your Hugging Face username: " HF_USERNAME | |
| if [ -z "$HF_USERNAME" ]; then | |
| echo "Error: Hugging Face username cannot be empty." | |
| exit 1 | |
| fi | |
| # Get Space name | |
| read -p "Enter a name for your Hugging Face Space (lowercase, no spaces): " SPACE_NAME | |
| if [ -z "$SPACE_NAME" ]; then | |
| echo "Error: Space name cannot be empty." | |
| exit 1 | |
| fi | |
| # Convert to lowercase and replace spaces with dashes | |
| SPACE_NAME=$(echo "$SPACE_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') | |
| # Create examples directory | |
| mkdir -p examples | |
| # Download example images | |
| python download_examples.py | |
| # Initialize git repository if not already initialized | |
| if [ ! -d .git ]; then | |
| git init | |
| fi | |
| # Create Hugging Face Space using the API | |
| echo "Creating Hugging Face Space..." | |
| python -c "from huggingface_hub import create_repo; create_repo(repo_id='$HF_USERNAME/$SPACE_NAME', repo_type='space', space_sdk='gradio')" | |
| # Add remote | |
| git remote add origin https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME || git remote set-url origin https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME | |
| # Add all files | |
| git add . | |
| # Commit | |
| git commit -m "Initial commit with proper configuration" | |
| # Push to Hugging Face | |
| echo "Pushing to Hugging Face Spaces..." | |
| git push -u origin main --force | |
| echo "Deployment complete! Your application is now available at: https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| echo "Note: It may take a few minutes for the application to build and deploy." |