|
|
|
|
|
""" |
|
|
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 = [] |
|
|
|
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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) |
|
|
|