ml_service / deploy.ps1
bldeaw's picture
Deploy to Hugging Face Spaces: Add application files and dependencies
ea2b6ec
Raw
History Blame Contribute Delete
3.58 kB
# Git deployment script for Hugging Face Spaces
# This script adds, commits, and pushes all necessary files
Write-Host "=== Preparing files for Hugging Face Spaces deployment ===" -ForegroundColor Cyan
# Change to project directory
Set-Location $PSScriptRoot
# Step 1: Remove git lock file if exists (in case of previous failed operations)
if (Test-Path .git\index.lock) {
Write-Host "Removing git lock file..." -ForegroundColor Yellow
Remove-Item .git\index.lock -Force -ErrorAction SilentlyContinue
}
# Step 2: Add core application files (required for API to work)
Write-Host "`nAdding core application files..." -ForegroundColor Green
git add app.py
git add preprocessing.py
git add model_utils.py
git add requirements.txt
git add Dockerfile
# Step 3: Add configuration files
Write-Host "Adding configuration files..." -ForegroundColor Green
git add .dockerignore
git add .gitignore
# Step 4: Add documentation files
Write-Host "Adding documentation files..." -ForegroundColor Green
git add README_HF_SPACE.md
git add DEPLOYMENT.md
git add DEPLOYMENT_SUMMARY.md
git add README.md
# Step 5: Add models directory (if exists and not in .gitignore)
if (Test-Path models) {
Write-Host "Checking models directory..." -ForegroundColor Yellow
# Check if models/ is in .gitignore
$gitignoreContent = Get-Content .gitignore -ErrorAction SilentlyContinue
if ($gitignoreContent -notmatch "^models/") {
Write-Host "Adding models directory..." -ForegroundColor Green
git add models/
} else {
Write-Host "WARNING: models/ is in .gitignore. You may need to force add it:" -ForegroundColor Yellow
Write-Host " git add -f models/" -ForegroundColor Yellow
}
}
# Step 6: Show status
Write-Host "`n=== Files staged for commit ===" -ForegroundColor Cyan
git status --short
# Step 7: Commit
Write-Host "`n=== Committing changes ===" -ForegroundColor Cyan
$commitMessage = "Deploy to Hugging Face Spaces: Add application files and dependencies
- Add FastAPI application (app.py)
- Add preprocessing module (preprocessing.py)
- Add model utilities (model_utils.py)
- Add Dockerfile for HF Spaces deployment
- Add requirements.txt
- Add deployment documentation
- Add configuration files"
git commit -m $commitMessage
if ($LASTEXITCODE -eq 0) {
Write-Host "`n=== Commit successful! ===" -ForegroundColor Green
# Step 8: Push
Write-Host "`n=== Pushing to remote ===" -ForegroundColor Cyan
Write-Host "Note: You may need to authenticate for push" -ForegroundColor Yellow
git push
if ($LASTEXITCODE -eq 0) {
Write-Host "`n=== Deployment files pushed successfully! ===" -ForegroundColor Green
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "1. Go to your Hugging Face Space" -ForegroundColor White
Write-Host "2. Wait for automatic rebuild" -ForegroundColor White
Write-Host "3. Check logs if build fails" -ForegroundColor White
} else {
Write-Host "`n=== Push failed ===" -ForegroundColor Red
Write-Host "You may need to:" -ForegroundColor Yellow
Write-Host "1. Set up authentication (git credential or token)" -ForegroundColor White
Write-Host "2. Check remote URL: git remote -v" -ForegroundColor White
Write-Host "3. Try: git push origin main" -ForegroundColor White
}
} else {
Write-Host "`n=== Commit failed ===" -ForegroundColor Red
Write-Host "Check git status and resolve any conflicts" -ForegroundColor Yellow
}
Write-Host "`n=== Script completed ===" -ForegroundColor Cyan