File size: 6,218 Bytes
3d2f143 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# Hugging Face Model Hub Deployment Script
# This script automates the deployment of your model to Hugging Face
Write-Host "`n" -ForegroundColor Green
Write-Host "=" * 70 -ForegroundColor Green
Write-Host "π CALIFORNIA HOUSE PRICE PREDICTION - HUGGING FACE DEPLOYMENT" -ForegroundColor Green
Write-Host "=" * 70 -ForegroundColor Green
Write-Host "`n"
# Step 1: Check if HF CLI is installed
Write-Host "STEP 1: Checking Hugging Face CLI..." -ForegroundColor Cyan
try {
$hfVersion = huggingface-cli --version 2>$null
Write-Host "β
Hugging Face CLI is installed: $hfVersion" -ForegroundColor Green
}
catch {
Write-Host "β Hugging Face CLI is not installed" -ForegroundColor Red
Write-Host "Installing Hugging Face CLI..." -ForegroundColor Yellow
pip install huggingface_hub
Write-Host "β
Hugging Face CLI installed" -ForegroundColor Green
}
Write-Host "`n"
# Step 2: Check authentication
Write-Host "STEP 2: Checking Hugging Face authentication..." -ForegroundColor Cyan
Write-Host "You need to be logged in to Hugging Face to deploy." -ForegroundColor Yellow
Write-Host "If you don't have an account, create one at https://huggingface.co/join" -ForegroundColor Yellow
Write-Host "`n"
$isAuthenticated = huggingface-cli whoami 2>$null
if (-not $isAuthenticated) {
Write-Host "You are not logged in. Starting login process..." -ForegroundColor Yellow
huggingface-cli login
$isAuthenticated = huggingface-cli whoami
}
if ($isAuthenticated) {
Write-Host "β
You are logged in as: $isAuthenticated" -ForegroundColor Green
}
else {
Write-Host "β Login failed. Cannot continue." -ForegroundColor Red
exit 1
}
Write-Host "`n"
# Step 3: Check Git LFS
Write-Host "STEP 3: Checking Git LFS..." -ForegroundColor Cyan
try {
$gitLfsVersion = git lfs version 2>$null
Write-Host "β
Git LFS is installed" -ForegroundColor Green
}
catch {
Write-Host "β Git LFS is not installed" -ForegroundColor Red
Write-Host "Please install Git LFS from: https://git-lfs.github.com/" -ForegroundColor Yellow
exit 1
}
Write-Host "`n"
# Step 4: Get repository name
Write-Host "STEP 4: Repository Configuration" -ForegroundColor Cyan
$repoName = "house-price-prediction"
Write-Host "Repository name: $repoName" -ForegroundColor White
# Get username
$username = huggingface-cli whoami
$repoUrl = "https://huggingface.co/$username/$repoName"
Write-Host "Repository URL: $repoUrl" -ForegroundColor White
Write-Host "`n"
# Step 5: Initialize Git LFS for model files
Write-Host "STEP 5: Setting up Git LFS..." -ForegroundColor Cyan
Write-Host "Initializing Git LFS for large model files..." -ForegroundColor White
git lfs install
git lfs track "*.joblib"
Write-Host "β
Git LFS configured" -ForegroundColor Green
Write-Host "`n"
# Step 6: Initialize git repository if not already done
Write-Host "STEP 6: Initializing Git Repository..." -ForegroundColor Cyan
if (-not (Test-Path ".git")) {
Write-Host "Initializing new git repository..." -ForegroundColor White
git init
git config user.name "House Price Predictor Bot"
git config user.email "[email protected]"
Write-Host "β
Git repository initialized" -ForegroundColor Green
}
else {
Write-Host "β
Git repository already initialized" -ForegroundColor Green
}
Write-Host "`n"
# Step 7: Add and commit files
Write-Host "STEP 7: Staging files..." -ForegroundColor Cyan
Write-Host "Adding all files to git..." -ForegroundColor White
git add .
Write-Host "β
Files staged" -ForegroundColor Green
Write-Host "`n"
Write-Host "STEP 8: Committing changes..." -ForegroundColor Cyan
$commitMessage = "Initial commit: California House Price Prediction Model"
git commit -m $commitMessage --allow-empty
Write-Host "β
Changes committed" -ForegroundColor Green
Write-Host "`n"
# Step 9: Set remote and push
Write-Host "STEP 9: Pushing to Hugging Face..." -ForegroundColor Cyan
# Remove existing remote if it exists
git remote rm origin 2>$null
# Add new remote
Write-Host "Adding remote: $repoUrl" -ForegroundColor White
git remote add origin $repoUrl
Write-Host "Pushing to Hugging Face (this may take a few minutes)..." -ForegroundColor White
Write-Host "Note: Large model files (41.4 MB) may take time to upload" -ForegroundColor Yellow
git push -u origin main --force
if ($LASTEXITCODE -eq 0) {
Write-Host "β
Push successful!" -ForegroundColor Green
}
else {
Write-Host "β οΈ Push completed with some warnings (this is usually okay)" -ForegroundColor Yellow
}
Write-Host "`n"
# Step 10: Verify deployment
Write-Host "STEP 10: Verifying deployment..." -ForegroundColor Cyan
Write-Host "Your model is now being processed by Hugging Face..." -ForegroundColor White
Write-Host "`n"
Write-Host "=" * 70 -ForegroundColor Green
Write-Host "π DEPLOYMENT COMPLETE!" -ForegroundColor Green
Write-Host "=" * 70 -ForegroundColor Green
Write-Host "`n"
Write-Host "Your model has been successfully uploaded to Hugging Face!" -ForegroundColor Green
Write-Host "`n"
Write-Host "π Model URL: $repoUrl" -ForegroundColor Cyan
Write-Host "`n"
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host "1. Visit your model page: $repoUrl" -ForegroundColor White
Write-Host "2. Verify all files are present (README.md, *.joblib, etc.)" -ForegroundColor White
Write-Host "3. Add additional metadata on the web interface if desired" -ForegroundColor White
Write-Host "4. Share your model with the community!" -ForegroundColor White
Write-Host "`n"
Write-Host "Optional - Add model tags on Hugging Face web interface:" -ForegroundColor Yellow
Write-Host "- tabular-regression" -ForegroundColor White
Write-Host "- scikit-learn" -ForegroundColor White
Write-Host "- random-forest" -ForegroundColor White
Write-Host "- house-prices" -ForegroundColor White
Write-Host "- california-housing" -ForegroundColor White
Write-Host "`n"
Write-Host "π Learn more about your model card:" -ForegroundColor Cyan
Write-Host "https://huggingface.co/docs/hub/models-cards" -ForegroundColor White
Write-Host "`n"
|