#!/bin/bash # Hugging Face Space Deployment Script for Khmer OCR echo "==========================================" echo "Khmer OCR-OCM - Hugging Face Deployment" echo "==========================================" echo "" # Check if Git LFS is installed if ! command -v git-lfs &> /dev/null; then echo "⚠️ Git LFS is not installed!" echo "Please install Git LFS first:" echo " Ubuntu/Debian: sudo apt-get install git-lfs" echo " macOS: brew install git-lfs" echo " Windows: Download from https://git-lfs.github.com/" exit 1 fi # Get Hugging Face username read -p "Enter your Hugging Face username: " HF_USERNAME # Get Space name read -p "Enter your Space name (default: khmer-ocr): " SPACE_NAME SPACE_NAME=${SPACE_NAME:-khmer-ocr} # Check if model file exists if [ ! -f "crnn_khmer_official_natural_v4.pth" ]; then echo "" echo "⚠️ Model file not found: crnn_khmer_official_natural_v4.pth" read -p "Enter the path to your model file: " MODEL_PATH if [ -f "$MODEL_PATH" ]; then cp "$MODEL_PATH" crnn_khmer_official_natural_v4.pth echo "✓ Model file copied" else echo "❌ Model file not found at: $MODEL_PATH" exit 1 fi fi # Clone the Space repository echo "" echo "Cloning your Hugging Face Space..." REPO_URL="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" if [ -d "$SPACE_NAME" ]; then echo "⚠️ Directory $SPACE_NAME already exists" read -p "Remove and re-clone? (y/n): " CONFIRM if [ "$CONFIRM" = "y" ]; then rm -rf "$SPACE_NAME" else echo "Deployment cancelled" exit 1 fi fi git clone "$REPO_URL" "$SPACE_NAME" if [ $? -ne 0 ]; then echo "❌ Failed to clone repository" echo "Make sure you've created the Space on Hugging Face first:" echo " https://huggingface.co/new-space" exit 1 fi # Move into the directory cd "$SPACE_NAME" # Initialize Git LFS echo "" echo "Setting up Git LFS..." git lfs install git lfs track "*.pth" # Copy files echo "" echo "Copying files..." cp ../.gitattributes . cp ../app.py . cp ../requirements.txt . cp ../packages.txt . cp ../README.md . cp ../crnn_khmer_official_natural_v4.pth . # Add and commit echo "" echo "Committing files..." git add . git commit -m "Deploy Khmer OCR model and Gradio app" # Push echo "" echo "Pushing to Hugging Face..." git push if [ $? -eq 0 ]; then echo "" echo "==========================================" echo "✅ Deployment Successful!" echo "==========================================" echo "" echo "Your Space is now building at:" echo " $REPO_URL" echo "" echo "It will take 2-5 minutes to build." echo "Check the status on the Space page." echo "" else echo "" echo "❌ Push failed" echo "Please check your Hugging Face credentials" echo "You may need to authenticate with:" echo " git config credential.helper store" echo " huggingface-cli login" fi