# =========================================== # Script de déploiement final pour Hugging Face Spaces # HOLOKIA-AVATAR - Avatar 3D Interactif # =========================================== param( [switch]$Help, [string]$HuggingFaceToken = "" ) # Configuration $HF_USERNAME = "DataSage12" $SPACE_NAME = "avatar-v2" $REPO_URL = "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" # Fonctions utilitaires function Write-Info { param([string]$Message) Write-Host "[INFO] $Message" -ForegroundColor Blue } function Write-Success { param([string]$Message) Write-Host "[SUCCESS] $Message" -ForegroundColor Green } function Write-Warning { param([string]$Message) Write-Host "[WARNING] $Message" -ForegroundColor Yellow } function Write-Error { param([string]$Message) Write-Host "[ERROR] $Message" -ForegroundColor Red } # Aide if ($Help) { Write-Host "Usage: .\deploy_to_hf_final.ps1 [OPTIONS]" Write-Host "" Write-Host "Options:" Write-Host " -Help Afficher cette aide" Write-Host " -HuggingFaceToken Token d'accès Hugging Face (optionnel)" Write-Host "" Write-Host "Ce script déploie HOLOKIA-AVATAR sur Hugging Face Spaces." Write-Host "" Write-Host "Variables d'environnement requises:" Write-Host " GROQ_API_KEY Clé API Groq" Write-Host "" exit 0 } # Vérifications préliminaires function Test-Requirements { Write-Info "Vérification des prérequis..." # Vérifier Git if (-not (Get-Command git -ErrorAction SilentlyContinue)) { Write-Error "Git n'est pas installé" exit 1 } # Vérifier Git LFS if (-not (Get-Command git-lfs -ErrorAction SilentlyContinue)) { Write-Error "Git LFS n'est pas installé" Write-Info "Installez Git LFS: winget install Git.Git-LFS" exit 1 } # Vérifier la clé API Groq $groqKey = $env:GROQ_API_KEY if (-not $groqKey) { Write-Error "GROQ_API_KEY n'est pas définie" Write-Info "Définissez votre clé API avec: `$env:GROQ_API_KEY = 'your_key_here'" exit 1 } Write-Success "Tous les prérequis sont satisfaits" Write-Info "Clé API Groq: $($groqKey.Substring(0, 10))..." } # Vérifier la structure du projet function Test-ProjectStructure { Write-Info "Vérification de la structure du projet..." $requiredFiles = @( "Dockerfile", "app.py", "requirements.txt", "Back-end\start_services.py", "Back-end\services\tts_service.py", "Back-end\services\stt_service.py", "Back-end\services\llm_service.py", "Back-end\services\live_stream_service.py", "frontend\package.json", "frontend\src\App.jsx" ) $missingFiles = @() foreach ($file in $requiredFiles) { if (-not (Test-Path $file)) { $missingFiles += $file } } if ($missingFiles.Count -gt 0) { Write-Error "Fichiers manquants:" foreach ($file in $missingFiles) { Write-Host " - $file" -ForegroundColor Red } exit 1 } Write-Success "Structure du projet validée" } # Configuration Git function Set-GitConfiguration { Write-Info "Configuration Git..." # Vérifier si le remote HF existe $existingRemote = git remote get-url origin 2>$null if ($existingRemote) { Write-Info "Remote existant: $existingRemote" if ($existingRemote -ne $REPO_URL) { Write-Info "Mise à jour du remote..." git remote set-url origin $REPO_URL } } else { Write-Info "Ajout du remote Hugging Face..." git remote add origin $REPO_URL } # Configurer l'authentification si un token est fourni if ($HuggingFaceToken) { Write-Info "Configuration de l'authentification..." $authUrl = $REPO_URL -replace "https://", "https://$HuggingFaceToken@" git remote set-url origin $authUrl } Write-Success "Configuration Git terminée" } # Test de l'image Docker function Test-DockerImage { Write-Info "Test de l'image Docker localement..." # Vérifier Docker if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Write-Warning "Docker n'est pas installé, test ignoré" return } try { # Construire l'image Write-Info "Construction de l'image Docker..." docker build -t holokia-avatar:test . # Tester l'image Write-Info "Test de l'image..." $containerId = docker run -d -p 7860:7860 -e GROQ_API_KEY=$env:GROQ_API_KEY holokia-avatar:test # Attendre le démarrage Write-Info "Attente du démarrage du service..." Start-Sleep -Seconds 60 # Vérifier la santé try { $response = Invoke-WebRequest -Uri "http://localhost:7860/health" -TimeoutSec 10 if ($response.StatusCode -eq 200) { Write-Success "Test local réussi" } else { Write-Warning "Test local: code de statut $($response.StatusCode)" } } catch { Write-Warning "Test local: service non accessible" } # Nettoyer docker stop $containerId docker rm $containerId docker rmi holokia-avatar:test } catch { Write-Warning "Erreur lors du test Docker: $($_.Exception.Message)" } } # Déploiement function Deploy-ToHuggingFace { Write-Info "Déploiement sur Hugging Face Spaces..." # Ajouter tous les fichiers git add . # Commit $commitMessage = "Deploy to Hugging Face Spaces - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" git commit -m $commitMessage # Push vers HF Write-Info "Push vers Hugging Face..." git push -u origin main Write-Success "Déploiement terminé!" } # Affichage des informations function Show-Info { Write-Info "Informations de déploiement:" Write-Host " - Utilisateur HF: $HF_USERNAME" Write-Host " - Nom du Space: $SPACE_NAME" Write-Host " - URL du Space: $REPO_URL" Write-Host " - Clé API Groq: $($env:GROQ_API_KEY.Substring(0, 10))..." Write-Host "" } # Fonction principale function Main { Write-Host "🚀 HOLOKIA-AVATAR - Déploiement sur Hugging Face Spaces" -ForegroundColor Cyan Write-Host "=====================================================" -ForegroundColor Cyan Write-Host "" Show-Info # Vérifications Test-Requirements Test-ProjectStructure # Test Docker (optionnel) Test-DockerImage # Configuration Git Set-GitConfiguration # Déploiement Deploy-ToHuggingFace Write-Host "" Write-Success "🎉 Déploiement terminé avec succès!" Write-Host "" Write-Info "Votre Space sera disponible à:" Write-Host " $REPO_URL" Write-Host "" Write-Info "N'oubliez pas d'ajouter votre clé API Groq dans les secrets du Space:" Write-Host " - Nom: GROQ_API_KEY" Write-Host " - Valeur: $env:GROQ_API_KEY" Write-Host "" Write-Info "Le Space va automatiquement se construire et démarrer dans quelques minutes." } # Exécution Main