Gym_Demo / check_deployment.py
Cuong2004's picture
first commit
f21948d
#!/usr/bin/env python3
"""
Check if the app is ready for deployment to Hugging Face Spaces
"""
import os
import sys
from pathlib import Path
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
def check_required_files():
"""Check if all required files exist"""
required_files = [
'app.py',
'requirements.txt',
'Dockerfile',
'.dockerignore',
'README.md',
'download_models.py',
'templates/index.html',
'static/css/style.css',
'static/js/script.js'
]
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
else:
logger.info(f"βœ… {file_path}")
if missing_files:
logger.error(f"❌ Missing files: {missing_files}")
return False
logger.info("βœ… All required files present")
return True
def check_directory_structure():
"""Check directory structure"""
required_dirs = [
'models',
'utils',
'static',
'static/css',
'static/js',
'static/uploads',
'templates'
]
missing_dirs = []
for dir_path in required_dirs:
if not Path(dir_path).exists():
missing_dirs.append(dir_path)
else:
logger.info(f"βœ… {dir_path}/")
if missing_dirs:
logger.error(f"❌ Missing directories: {missing_dirs}")
return False
logger.info("βœ… Directory structure correct")
return True
def check_imports():
"""Check if main imports work"""
try:
logger.info("πŸ” Testing imports...")
# Test Flask import
from flask import Flask
logger.info("βœ… Flask import OK")
# Test utils
import utils.suppress_warnings
logger.info("βœ… Utils import OK")
# Test models (skip if models not available)
try:
from models.model_loader import ModelLoader
logger.info("βœ… Models import OK")
except Exception as e:
logger.info(f"⚠️ Models import skipped (models will be downloaded on deployment): {e}")
logger.info("βœ… Critical imports successful")
return True
except ImportError as e:
logger.error(f"❌ Import error: {e}")
return False
def check_docker_setup():
"""Check Docker-related files"""
docker_files = ['Dockerfile', '.dockerignore']
for file_path in docker_files:
if not Path(file_path).exists():
logger.error(f"❌ Missing {file_path}")
return False
# Check file is not empty
if Path(file_path).stat().st_size == 0:
logger.error(f"❌ {file_path} is empty")
return False
logger.info(f"βœ… {file_path} exists and not empty")
return True
def check_readme():
"""Check README has Hugging Face metadata"""
readme_path = Path('README.md')
if not readme_path.exists():
logger.error("❌ README.md missing")
return False
content = readme_path.read_text(encoding='utf-8')
# Check for Hugging Face metadata
if not content.startswith('---'):
logger.error("❌ README.md missing Hugging Face metadata header")
return False
required_fields = ['title:', 'emoji:', 'sdk:', 'app_port:']
for field in required_fields:
if field not in content:
logger.error(f"❌ README.md missing field: {field}")
return False
logger.info("βœ… README.md has proper Hugging Face metadata")
return True
def main():
"""Main deployment check"""
logger.info("πŸš€ Checking deployment readiness for Hugging Face Spaces...")
logger.info("=" * 60)
checks = [
("Required Files", check_required_files),
("Directory Structure", check_directory_structure),
("Docker Setup", check_docker_setup),
("README Metadata", check_readme),
("Python Imports", check_imports),
]
passed = 0
failed = 0
for check_name, check_func in checks:
logger.info(f"\nπŸ” {check_name}...")
if check_func():
passed += 1
logger.info(f"βœ… {check_name} PASSED")
else:
failed += 1
logger.error(f"❌ {check_name} FAILED")
logger.info("\n" + "=" * 60)
logger.info(f"πŸ“Š Results: {passed} passed, {failed} failed")
if failed == 0:
logger.info("πŸŽ‰ Deployment ready! You can upload to Hugging Face Spaces.")
logger.info("πŸ’‘ Don't forget to:")
logger.info(" 1. Upload model weights to Hugging Face Model Hub")
logger.info(" 2. Update URLs in download_models.py")
logger.info(" 3. Test the space after deployment")
return 0
else:
logger.error("❌ Please fix the issues above before deploying")
return 1
if __name__ == "__main__":
sys.exit(main())