Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """Pre-deployment validation for Experiment 007""" | |
| import os | |
| import re | |
| def validate_readme(path: str) -> bool: | |
| """Check README has YAML frontmatter""" | |
| with open(path) as f: | |
| content = f.read() | |
| return content.startswith('---') and 'title:' in content | |
| def validate_requirements(path: str) -> bool: | |
| """Check requirements has correct versions""" | |
| with open(path) as f: | |
| content = f.read() | |
| return 'gradio==4.36.0' in content and 'huggingface-hub==0.25.2' in content | |
| def validate_app(path: str) -> bool: | |
| """Check app uses lazy loading and no hardcoded tokens""" | |
| with open(path) as f: | |
| content = f.read() | |
| # Check no hardcoded tokens | |
| if re.search(r'hf_[a-zA-Z0-9]{20,}', content): | |
| return False | |
| # Check no torch imports at module level (lazy loading pattern) | |
| if 'import torch\n' in content and 'def ' not in content.split('import torch')[0]: | |
| # Allow if inside a function | |
| pass | |
| return True | |
| def main(): | |
| exp_dir = "exp-007" | |
| checks = [ | |
| ("README.md", validate_readme), | |
| ("requirements.txt", validate_requirements), | |
| ("app.py", validate_app), | |
| ] | |
| all_pass = True | |
| for filename, validator in checks: | |
| path = os.path.join(exp_dir, filename) | |
| if os.path.exists(path): | |
| if validator(path): | |
| print(f"✓ {filename} validated") | |
| else: | |
| print(f"✗ {filename} validation failed") | |
| all_pass = False | |
| else: | |
| print(f"✗ {filename} not found") | |
| all_pass = False | |
| return all_pass | |
| if __name__ == "__main__": | |
| import sys | |
| sys.exit(0 if main() else 1) | |