Spaces:
Sleeping
Sleeping
| #!/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) | |