Spaces:
Sleeping
Sleeping
| # Script de vérification pour Hugging Face Spaces | |
| # Vérifie que tout est prêt pour le déploiement | |
| set -e | |
| # Colors | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' | |
| print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; } | |
| print_success() { echo -e "${GREEN}✅ $1${NC}"; } | |
| print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; } | |
| print_error() { echo -e "${RED}❌ $1${NC}"; } | |
| FAILURES=0 | |
| WARNINGS=0 | |
| echo "" | |
| print_info "🔍 Hugging Face Spaces Pre-Deployment Check" | |
| echo "================================================" | |
| echo "" | |
| # Test 1: Python version | |
| print_info "Test 1: Python version..." | |
| PYTHON_VERSION=$(python --version 2>&1 | awk '{print $2}') | |
| PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1) | |
| PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2) | |
| if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 12 ]; then | |
| print_success "Python $PYTHON_VERSION (>= 3.12)" | |
| else | |
| print_warning "Python $PYTHON_VERSION (recommended: >= 3.12)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| echo "" | |
| # Test 2: Required files | |
| print_info "Test 2: Required files..." | |
| REQUIRED_FILES=( | |
| "app.py" | |
| "app_api.py" | |
| "app_ui.py" | |
| "requirements.txt" | |
| "README.md" | |
| ".gitattributes" | |
| ) | |
| for file in "${REQUIRED_FILES[@]}"; do | |
| if [ -f "$file" ]; then | |
| print_success "$file exists" | |
| else | |
| print_error "$file NOT FOUND" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| done | |
| echo "" | |
| # Test 3: Required directories | |
| print_info "Test 3: Required directories..." | |
| REQUIRED_DIRS=( | |
| "detection" | |
| "api" | |
| "ui" | |
| "rfdetr" | |
| ) | |
| for dir in "${REQUIRED_DIRS[@]}"; do | |
| if [ -d "$dir" ]; then | |
| print_success "$dir/ exists" | |
| else | |
| print_error "$dir/ NOT FOUND" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| done | |
| echo "" | |
| # Test 4: model.pth | |
| print_info "Test 4: Model weights (model.pth)..." | |
| if [ -f "model.pth" ]; then | |
| SIZE=$(du -h model.pth | cut -f1) | |
| SIZE_BYTES=$(stat -f%z model.pth 2>/dev/null || stat -c%s model.pth) | |
| if [ $SIZE_BYTES -gt 100000000 ]; then # > 100MB | |
| print_success "model.pth exists ($SIZE)" | |
| # Check Git LFS | |
| if git lfs ls-files | grep -q "model.pth"; then | |
| print_success "model.pth tracked by Git LFS" | |
| else | |
| print_warning "model.pth NOT tracked by Git LFS (will fail on push)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| else | |
| print_warning "model.pth size: $SIZE (seems small, verify it's correct)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| else | |
| print_error "model.pth NOT FOUND" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| echo "" | |
| # Test 5: Git LFS | |
| print_info "Test 5: Git LFS configuration..." | |
| if command -v git-lfs &> /dev/null; then | |
| print_success "Git LFS installed" | |
| if git lfs env &> /dev/null; then | |
| print_success "Git LFS initialized" | |
| else | |
| print_warning "Git LFS not initialized" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| if grep -q "*.pth.*lfs" .gitattributes 2>/dev/null; then | |
| print_success ".gitattributes tracks *.pth" | |
| else | |
| print_error ".gitattributes doesn't track *.pth" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| else | |
| print_error "Git LFS not installed!" | |
| print_info " Install: brew install git-lfs (macOS) or sudo apt install git-lfs (Linux)" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| echo "" | |
| # Test 6: README.md frontmatter | |
| print_info "Test 6: README.md frontmatter (HF Spaces metadata)..." | |
| if [ -f "README.md" ]; then | |
| if head -n 1 README.md | grep -q "^---$"; then | |
| print_success "README.md has YAML frontmatter" | |
| # Check key fields | |
| if grep -q "^sdk: gradio" README.md; then | |
| print_success "sdk: gradio found" | |
| else | |
| print_warning "sdk: gradio not found" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| if grep -q "^app_file: app.py" README.md; then | |
| print_success "app_file: app.py found" | |
| else | |
| print_warning "app_file: app.py not found" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| if grep -q "^python_version:" README.md; then | |
| print_success "python_version specified" | |
| else | |
| print_warning "python_version not specified" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| else | |
| print_error "README.md missing YAML frontmatter" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| else | |
| print_error "README.md not found" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| echo "" | |
| # Test 7: requirements.txt | |
| print_info "Test 7: requirements.txt..." | |
| if [ -f "requirements.txt" ]; then | |
| if [ -s "requirements.txt" ]; then | |
| LINE_COUNT=$(wc -l < requirements.txt) | |
| if [ $LINE_COUNT -gt 5 ]; then | |
| print_success "requirements.txt looks complete ($LINE_COUNT lines)" | |
| else | |
| print_warning "requirements.txt seems minimal ($LINE_COUNT lines)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| # Check for critical dependencies | |
| if grep -q "gradio" requirements.txt; then | |
| print_success "gradio found in requirements.txt" | |
| else | |
| print_error "gradio NOT found in requirements.txt" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| if grep -q "torch" requirements.txt; then | |
| print_success "torch found in requirements.txt" | |
| else | |
| print_warning "torch not found (may be needed)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| else | |
| print_error "requirements.txt is empty" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| else | |
| print_error "requirements.txt not found" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| echo "" | |
| # Test 8: Python syntax | |
| print_info "Test 8: Python syntax validation..." | |
| for pyfile in app.py app_api.py app_ui.py; do | |
| if [ -f "$pyfile" ]; then | |
| if python -m py_compile "$pyfile" 2>/dev/null; then | |
| print_success "$pyfile syntax valid" | |
| else | |
| print_error "$pyfile has syntax errors" | |
| FAILURES=$((FAILURES + 1)) | |
| fi | |
| fi | |
| done | |
| echo "" | |
| # Test 9: Git repository | |
| print_info "Test 9: Git repository..." | |
| if [ -d ".git" ]; then | |
| print_success "Git repository initialized" | |
| # Check remote | |
| if git remote -v | grep -q "huggingface.co"; then | |
| REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "unknown") | |
| print_success "HF Space remote configured: $REMOTE_URL" | |
| else | |
| print_warning "No Hugging Face remote configured" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| # Check for uncommitted changes | |
| if [ -n "$(git status --porcelain)" ]; then | |
| print_warning "Uncommitted changes detected" | |
| WARNINGS=$((WARNINGS + 1)) | |
| else | |
| print_success "All changes committed" | |
| fi | |
| else | |
| print_warning "Not a git repository (will need git init)" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| echo "" | |
| # Test 10: Hugging Face CLI | |
| print_info "Test 10: Hugging Face CLI..." | |
| if command -v huggingface-cli &> /dev/null || command -v hf &> /dev/null; then | |
| print_success "Hugging Face CLI installed" | |
| # Check login | |
| if huggingface-cli whoami &> /dev/null 2>&1 || hf auth whoami &> /dev/null 2>&1; then | |
| USERNAME=$(huggingface-cli whoami 2>/dev/null || hf auth whoami 2>/dev/null | head -n1) | |
| print_success "Logged in as: $USERNAME" | |
| else | |
| print_warning "Not logged in to Hugging Face" | |
| print_info " Run: huggingface-cli login or hf login" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| else | |
| print_warning "Hugging Face CLI not installed" | |
| print_info " Install: pip install huggingface-hub" | |
| WARNINGS=$((WARNINGS + 1)) | |
| fi | |
| echo "" | |
| # Summary | |
| echo "================================================" | |
| if [ $FAILURES -eq 0 ] && [ $WARNINGS -eq 0 ]; then | |
| print_success "All checks passed! Ready to deploy! ✨" | |
| echo "" | |
| print_info "Next step: Run ./deploy_hf_space.sh" | |
| exit 0 | |
| elif [ $FAILURES -eq 0 ]; then | |
| print_warning "$WARNINGS warning(s) found" | |
| echo "" | |
| print_info "You can proceed, but consider fixing warnings" | |
| print_info "Next step: Run ./deploy_hf_space.sh" | |
| exit 0 | |
| else | |
| print_error "$FAILURES critical error(s) and $WARNINGS warning(s)" | |
| echo "" | |
| print_info "Please fix the errors before deploying" | |
| exit 1 | |
| fi | |