Spaces:
Sleeping
Sleeping
File size: 8,273 Bytes
ff03012 |
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
#!/bin/bash
# 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
|