Spaces:
Runtime error
Runtime error
# Script de déploiement automatisé pour Hugging Face Spaces | |
# Usage: ./deploy.sh <votre-username> <nom-du-space> | |
set -e # Arrêter en cas d'erreur | |
# Couleurs pour l'affichage | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' # No Color | |
# Fonction pour afficher les messages | |
print_status() { | |
echo -e "${BLUE}[INFO]${NC} $1" | |
} | |
print_success() { | |
echo -e "${GREEN}[SUCCESS]${NC} $1" | |
} | |
print_warning() { | |
echo -e "${YELLOW}[WARNING]${NC} $1" | |
} | |
print_error() { | |
echo -e "${RED}[ERROR]${NC} $1" | |
} | |
# Vérification des arguments | |
if [ $# -ne 2 ]; then | |
print_error "Usage: $0 <votre-username> <nom-du-space>" | |
print_error "Exemple: $0 john sentiment-audio-analyzer" | |
exit 1 | |
fi | |
USERNAME=$1 | |
SPACE_NAME=$2 | |
SPACE_URL="https://huggingface.co/spaces/$USERNAME/$SPACE_NAME" | |
print_status "Démarrage du déploiement pour $SPACE_URL" | |
# 1. Vérification de la structure du projet | |
print_status "Vérification de la structure du projet..." | |
required_files=( | |
"app.py" | |
"requirements_hf.txt" | |
"config.yaml" | |
"README_HF.md" | |
".gitattributes" | |
"src/__init__.py" | |
"src/transcription.py" | |
"src/sentiment.py" | |
"src/multimodal.py" | |
"src/inference.py" | |
) | |
for file in "${required_files[@]}"; do | |
if [ ! -f "$file" ]; then | |
print_error "Fichier manquant: $file" | |
exit 1 | |
fi | |
done | |
print_success "Structure du projet validée" | |
# 2. Test du projet | |
print_status "Exécution des tests..." | |
if [ -f "test_deployment.py" ]; then | |
python test_deployment.py | |
if [ $? -ne 0 ]; then | |
print_error "Les tests ont échoué. Corrigez les problèmes avant de continuer." | |
exit 1 | |
fi | |
print_success "Tests passés avec succès" | |
else | |
print_warning "Script de test non trouvé, passage des tests..." | |
fi | |
# 3. Vérification de Git | |
print_status "Vérification de Git..." | |
if ! command -v git &> /dev/null; then | |
print_error "Git n'est pas installé" | |
exit 1 | |
fi | |
# 4. Initialisation Git si nécessaire | |
if [ ! -d ".git" ]; then | |
print_status "Initialisation du repository Git..." | |
git init | |
git add . | |
git commit -m "Initial commit" | |
fi | |
# 5. Ajout du remote Hugging Face | |
print_status "Configuration du remote Hugging Face..." | |
# Supprimer l'ancien remote s'il existe | |
git remote remove hf 2>/dev/null || true | |
# Ajouter le nouveau remote | |
git remote add hf "https://huggingface.co/spaces/$USERNAME/$SPACE_NAME" | |
print_success "Remote configuré: $SPACE_URL" | |
# 6. Préparation du commit | |
print_status "Préparation du commit..." | |
# Ajouter tous les fichiers | |
git add . | |
# Créer le commit | |
git commit -m "Deploy: Analyse de sentiment audio v1.0" || { | |
print_warning "Aucun changement détecté, commit ignoré" | |
} | |
# 7. Déploiement | |
print_status "Déploiement sur Hugging Face Spaces..." | |
# Demander confirmation | |
read -p "Voulez-vous déployer maintenant ? (y/N): " -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
print_warning "Déploiement annulé" | |
exit 0 | |
fi | |
# Pousser vers Hugging Face | |
print_status "Poussage du code..." | |
git push hf main | |
print_success "Déploiement terminé avec succès !" | |
print_success "Votre Space est accessible à: $SPACE_URL" | |
# 8. Instructions post-déploiement | |
echo | |
print_status "Instructions post-déploiement:" | |
echo "1. Allez sur $SPACE_URL" | |
echo "2. Attendez que le build se termine (peut prendre 5-10 minutes)" | |
echo "3. Testez votre application" | |
echo "4. Consultez les logs en cas de problème" | |
# 9. Vérification du statut | |
print_status "Vérification du statut du Space..." | |
echo "Vous pouvez vérifier le statut à: $SPACE_URL" | |
print_success "Script de déploiement terminé !" |