#!/usr/bin/env python3 """ Validation script for Hugging Face Spaces Docker deployment """ import os import sys from pathlib import Path def check_docker_setup(): """Check if the application is ready for Docker deployment""" print("šŸ” Validating Docker setup for Hugging Face Spaces...") issues = [] warnings = [] # Check required files required_files = [ 'Dockerfile', 'app.py', 'requirements.txt', 'main.py', 'config_manager.py' ] for file in required_files: if not Path(file).exists(): issues.append(f"Missing required file: {file}") else: print(f"āœ… Found {file}") # Check Dockerfile if Path('Dockerfile').exists(): with open('Dockerfile', 'r') as f: dockerfile_content = f.read() if 'EXPOSE 7860' not in dockerfile_content: issues.append("Dockerfile missing EXPOSE 7860") if 'GRADIO_SERVER_PORT=7860' not in dockerfile_content: warnings.append("Dockerfile should set GRADIO_SERVER_PORT=7860") if 'python app.py' not in dockerfile_content: issues.append("Dockerfile should run 'python app.py' as CMD") print("āœ… Dockerfile configuration validated") # Check requirements.txt if Path('requirements.txt').exists(): with open('requirements.txt', 'r') as f: requirements = f.read() if 'gradio' not in requirements: issues.append("requirements.txt missing gradio dependency") if 'flask' not in requirements.lower(): issues.append("requirements.txt missing Flask dependency") print("āœ… Requirements validated") # Check app.py configuration if Path('app.py').exists(): with open('app.py', 'r') as f: app_content = f.read() if 'server_port=7860' not in app_content: issues.append("app.py should launch on port 7860") if 'HUGGINGFACE_SPACES' not in app_content: warnings.append("app.py should set HUGGINGFACE_SPACES environment variable") print("āœ… app.py configuration validated") # Check for removed deployment files removed_files = [ 'render_start.py', 'gunicorn.conf.py', 'requirements.render.txt' ] for file in removed_files: if Path(file).exists(): warnings.append(f"Should remove deployment file: {file}") print("\n" + "="*50) if issues: print("āŒ Issues found:") for issue in issues: print(f" • {issue}") if warnings: print("āš ļø Warnings:") for warning in warnings: print(f" • {warning}") if not issues and not warnings: print("āœ… Docker setup is ready for Hugging Face Spaces!") print("\nšŸš€ Next steps:") print("1. Create a new Space on Hugging Face") print("2. Choose 'Docker' as the SDK") print("3. Upload your code to the Space repository") print("4. Set your API keys in Space secrets") print("5. Your Space will automatically build and deploy!") elif not issues: print("āœ… Docker setup is mostly ready!") print("Consider addressing the warnings above.") else: print("āŒ Please fix the issues above before deploying.") return False return True if __name__ == "__main__": success = check_docker_setup() sys.exit(0 if success else 1)