|
|
|
|
|
|
|
|
|
function Write-ColorOutput($ForegroundColor) { |
|
$fc = $host.UI.RawUI.ForegroundColor |
|
$host.UI.RawUI.ForegroundColor = $ForegroundColor |
|
if ($args) { |
|
Write-Output $args |
|
} |
|
else { |
|
$input | Write-Output |
|
} |
|
$host.UI.RawUI.ForegroundColor = $fc |
|
} |
|
|
|
|
|
function PrintBlue($message) { |
|
Write-ColorOutput Blue $message |
|
} |
|
|
|
function PrintGreen($message) { |
|
Write-ColorOutput Green $message |
|
} |
|
|
|
function PrintRed($message) { |
|
Write-ColorOutput Red $message |
|
} |
|
|
|
|
|
$projectPath = "D:\ARAFAT_GUI-V2.9\files\trained-bot\trained-bot" |
|
|
|
|
|
PrintBlue "Navigating to project directory: $projectPath" |
|
Set-Location -Path $projectPath |
|
|
|
PrintBlue "=== Hugging Face Spaces Deployment Fix ===" |
|
|
|
|
|
PrintBlue "`nChecking for huggingface_hub..." |
|
$pipList = pip list |
|
if ($pipList -match "huggingface-hub") { |
|
PrintGreen "huggingface_hub is already installed." |
|
} |
|
else { |
|
PrintBlue "Installing huggingface_hub..." |
|
pip install -U huggingface_hub |
|
} |
|
|
|
|
|
PrintBlue "`nMaking sure huggingface-cli is available..." |
|
try { |
|
$null = Get-Command huggingface-cli -ErrorAction Stop |
|
PrintGreen "huggingface-cli is available." |
|
} |
|
catch { |
|
PrintRed "huggingface-cli is not available. Reinstalling huggingface_hub..." |
|
pip install -U --force-reinstall huggingface_hub |
|
} |
|
|
|
|
|
PrintBlue "`nLogging in to Hugging Face..." |
|
PrintRed "IMPORTANT: Do not share your token in public chats or forums" |
|
$HF_TOKEN = Read-Host "Enter your Hugging Face token" -AsSecureString |
|
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($HF_TOKEN) |
|
$HFToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) |
|
|
|
|
|
$env:HUGGINGFACE_TOKEN = $HFToken |
|
|
|
|
|
PrintBlue "`nAttempting login..." |
|
$HFToken | huggingface-cli login |
|
|
|
|
|
PrintBlue "`nChecking project structure..." |
|
|
|
|
|
if (Test-Path "README.md") { |
|
PrintGreen "README.md exists. Checking content..." |
|
$readmeContent = Get-Content "README.md" -Raw |
|
if ($readmeContent -match "app_file:" -and $readmeContent -match "sdk: gradio") { |
|
PrintGreen "README.md appears to have the right content." |
|
} |
|
else { |
|
PrintRed "README.md may be missing required metadata." |
|
PrintBlue "Adding proper metadata to README.md..." |
|
|
|
Copy-Item "README.md" "README.md.bak" |
|
|
|
|
|
$APP_FILE = "app.py" |
|
if (Test-Path "app.py") { |
|
$APP_FILE = "app.py" |
|
} |
|
else { |
|
$INPUT_APP_FILE = Read-Host "Enter your main app file name (default: app.py)" |
|
if (-not [string]::IsNullOrEmpty($INPUT_APP_FILE)) { |
|
$APP_FILE = $INPUT_APP_FILE |
|
} |
|
} |
|
|
|
|
|
$TITLE = "Arafat Vehicle Management" |
|
$INPUT_TITLE = Read-Host "Enter your app title (default: Arafat Vehicle Management)" |
|
if (-not [string]::IsNullOrEmpty($INPUT_TITLE)) { |
|
$TITLE = $INPUT_TITLE |
|
} |
|
|
|
$newReadmeContent = "---`ntitle: $TITLE`napp_file: $APP_FILE`nsdk: gradio`nsdk_version: 4.44.1`n---`n$readmeContent" |
|
Set-Content -Path "README.md" -Value $newReadmeContent |
|
PrintGreen "Updated README.md with proper metadata." |
|
} |
|
} |
|
else { |
|
PrintRed "README.md doesn't exist. Creating it..." |
|
|
|
$APP_FILE = "app.py" |
|
if (Test-Path "app.py") { |
|
$APP_FILE = "app.py" |
|
} |
|
else { |
|
$INPUT_APP_FILE = Read-Host "Enter your main app file name (default: app.py)" |
|
if (-not [string]::IsNullOrEmpty($INPUT_APP_FILE)) { |
|
$APP_FILE = $INPUT_APP_FILE |
|
} |
|
} |
|
|
|
$TITLE = "Arafat Vehicle Management" |
|
$INPUT_TITLE = Read-Host "Enter your app title (default: Arafat Vehicle Management)" |
|
if (-not [string]::IsNullOrEmpty($INPUT_TITLE)) { |
|
$TITLE = $INPUT_TITLE |
|
} |
|
|
|
$newReadmeContent = "---`ntitle: $TITLE`napp_file: $APP_FILE`nsdk: gradio`nsdk_version: 4.44.1`n---`n`n# $TITLE`n`nA vehicle management system built with Gradio." |
|
Set-Content -Path "README.md" -Value $newReadmeContent |
|
PrintGreen "Created README.md with proper metadata." |
|
} |
|
|
|
|
|
PrintBlue "`nChecking requirements.txt..." |
|
if (Test-Path "requirements.txt") { |
|
PrintGreen "requirements.txt exists." |
|
|
|
$requirementsContent = Get-Content "requirements.txt" -Raw |
|
if ($requirementsContent -match "gradio") { |
|
PrintGreen "Gradio is listed in requirements." |
|
} |
|
else { |
|
PrintRed "Gradio may be missing in requirements.txt." |
|
PrintBlue "Adding gradio to requirements.txt..." |
|
Add-Content -Path "requirements.txt" -Value "gradio==4.44.1" |
|
PrintGreen "Added gradio to requirements.txt" |
|
} |
|
} |
|
else { |
|
PrintRed "requirements.txt doesn't exist. Creating it..." |
|
|
|
$requirementsContent = "gradio==4.44.1`ngTTS==2.4.0`npygame==2.5.2" |
|
Set-Content -Path "requirements.txt" -Value $requirementsContent |
|
PrintGreen "Created requirements.txt with basic dependencies." |
|
} |
|
|
|
|
|
PrintBlue "`nChecking for docs directory and data file..." |
|
if (Test-Path "docs") { |
|
PrintGreen "docs directory exists." |
|
if (Test-Path "docs\your_data.csv") { |
|
PrintGreen "Data file exists." |
|
} |
|
else { |
|
PrintRed "Data file 'docs\your_data.csv' not found." |
|
PrintBlue "Please ensure your data file is in the correct location and properly named." |
|
} |
|
} |
|
else { |
|
PrintRed "docs directory doesn't exist. Creating it..." |
|
New-Item -Path "docs" -ItemType Directory |
|
PrintGreen "Created docs directory." |
|
PrintBlue "Please place your data file as 'docs\your_data.csv'." |
|
} |
|
|
|
|
|
PrintBlue "`nChecking .gitignore..." |
|
if (Test-Path ".gitignore") { |
|
PrintGreen ".gitignore exists." |
|
} |
|
else { |
|
PrintBlue "Creating .gitignore..." |
|
$gitignoreContent = "__pycache__/`n*.py[cod]`n*`$py.class`n*.so`n.Python`nenv/`nbuild/`ndevelop-eggs/`ndist/`ndownloads/`neggs/`n.eggs/`nlib/`nlib64/`nparts/`nsdist/`nvar/`n*.egg-info/`n.installed.cfg`n*.egg`n.env`n.venv`nenv/`nvenv/`nENV/`nenv.bak/`nvenv.bak/`nstatic/*.mp3`nflagged/`n*.log" |
|
Set-Content -Path ".gitignore" -Value $gitignoreContent |
|
PrintGreen "Created .gitignore file." |
|
} |
|
|
|
|
|
PrintBlue "`nPreparing for deployment..." |
|
$SPACE_NAME = Read-Host "Enter your Hugging Face Space name (e.g., yourusername/app-name)" |
|
|
|
if ([string]::IsNullOrEmpty($SPACE_NAME)) { |
|
PrintRed "No Space name provided. Cannot continue with deployment." |
|
exit 1 |
|
} |
|
|
|
|
|
PrintBlue "`nAttempting to deploy to $SPACE_NAME..." |
|
PrintBlue "This may take a few minutes..." |
|
|
|
|
|
if (Test-Path ".git") { |
|
PrintGreen "Git repository detected." |
|
|
|
|
|
git add . |
|
|
|
|
|
git commit -m "Fix deployment configuration" |
|
|
|
|
|
$remotes = git remote |
|
if ($remotes -notcontains "huggingface") { |
|
git remote add huggingface "https://huggingface.co/spaces/$SPACE_NAME" |
|
} |
|
|
|
|
|
PrintBlue "Pushing to Hugging Face..." |
|
git push -f huggingface main |
|
} |
|
else { |
|
PrintBlue "Not a Git repository. Using Hugging Face Hub API to deploy..." |
|
|
|
|
|
$pythonScript = @" |
|
from huggingface_hub import HfApi |
|
import os |
|
|
|
api = HfApi() |
|
api.create_repo( |
|
repo_id='$SPACE_NAME', |
|
repo_type='space', |
|
space_sdk='gradio', |
|
private=False |
|
) |
|
api.upload_folder( |
|
folder_path='.', |
|
repo_id='$SPACE_NAME', |
|
repo_type='space', |
|
ignore_patterns=['.git', '.gitignore', '*.pyc', '__pycache__', '*.log'] |
|
) |
|
print('Deployment completed!') |
|
"@ |
|
|
|
|
|
$tempFile = [System.IO.Path]::GetTempFileName() + ".py" |
|
Set-Content -Path $tempFile -Value $pythonScript |
|
|
|
|
|
python $tempFile |
|
|
|
|
|
Remove-Item $tempFile |
|
} |
|
|
|
PrintBlue "`nDeployment process completed!" |
|
PrintBlue "Visit your Space at: https://huggingface.co/spaces/$SPACE_NAME" |
|
PrintBlue "Note: It may take a few minutes for your Space to build and become available." |
|
|
|
|
|
PrintGreen "`n===================================" |
|
PrintGreen "Deployment fix script completed!" |
|
PrintGreen "===================================" |
|
|