File size: 1,292 Bytes
a321b61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Run smoke test notebook on HuggingFace Space
"""
import subprocess
import sys
import os
from pathlib import Path

def run_notebook(notebook_path):
    """Execute a Jupyter notebook using nbconvert"""
    print(f"Running notebook: {notebook_path}")

    cmd = [
        "jupyter", "nbconvert",
        "--to", "notebook",
        "--execute",
        "--inplace",
        "--ExecutePreprocessor.timeout=600",
        str(notebook_path)
    ]

    result = subprocess.run(cmd, capture_output=True, text=True)

    if result.returncode == 0:
        print(f"✓ Successfully executed {notebook_path}")
        return True
    else:
        print(f"✗ Error executing {notebook_path}")
        print(f"STDOUT: {result.stdout}")
        print(f"STDERR: {result.stderr}")
        return False

if __name__ == "__main__":
    # Set HF token from environment
    if "HF_TOKEN" not in os.environ:
        print("Warning: HF_TOKEN not set in environment")
        print("Set it with: export HF_TOKEN='your_token'")

    # Run smoke test
    notebook = Path("/data/inference_smoke_test.ipynb")

    if not notebook.exists():
        print(f"Error: Notebook not found at {notebook}")
        sys.exit(1)

    success = run_notebook(notebook)
    sys.exit(0 if success else 1)