File size: 1,891 Bytes
de6f049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Pre-deploy validation script."""
import os
import re

def validate_experiment(path):
    errors = []
    
    # Check README.md has YAML frontmatter
    readme_path = os.path.join(path, "README.md")
    if os.path.exists(readme_path):
        with open(readme_path) as f:
            content = f.read()
        if not content.startswith("---"):
            errors.append("README.md missing YAML frontmatter")
    else:
        errors.append("README.md not found")
    
    # Check requirements.txt has gradio==4.36.0
    req_path = os.path.join(path, "requirements.txt")
    if os.path.exists(req_path):
        with open(req_path) as f:
            content = f.read()
        if "gradio==4.36.0" not in content:
            errors.append("requirements.txt missing pinned gradio==4.36.0")
        if "huggingface_hub==0.25.2" not in content:
            errors.append("requirements.txt missing pinned huggingface_hub==0.25.2")
    else:
        errors.append("requirements.txt not found")
    
    # Check app.py uses lazy loading
    app_path = os.path.join(path, "app.py")
    if os.path.exists(app_path):
        with open(app_path) as f:
            content = f.read()
        if "import torch" in content and "def " in content.split("def ")[0]:
            errors.append("torch imported at module level (not lazy)")
        if "hardcoded" in content.lower() or "api_key" in content.lower():
            if "os.environ" not in content:
                errors.append("Possible hardcoded tokens")
    else:
        errors.append("app.py not found")
    
    if errors:
        print("VALIDATION FAILED:")
        for e in errors:
            print(f"  - {e}")
        return False
    
    print("✅ Validation passed")
    return True

if __name__ == "__main__":
    import sys
    path = sys.argv[1] if len(sys.argv) > 1 else "."
    validate_experiment(path)