Download src/sealcell/cli.py from sroecker/seal-cell: direct link, hf CLI and curl.
- Browser
- Download file 4.02 kB
-
https://huggingface.co/spaces/sroecker/seal-cell/resolve/main/src/sealcell/cli.py
- Command line
-
hf download hf://spaces/sroecker/seal-cell/src/sealcell/cli.py
-
curl -L -o cli.py https://huggingface.co/spaces/sroecker/seal-cell/resolve/main/src/sealcell/cli.py
4.02 kB
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| from .config import ROOT | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="Local synthetic sealing cell and GLiNER evaluation" | |
| ) | |
| parser.add_argument( | |
| "--device", | |
| choices=["cpu", "mps"], | |
| default="cpu", | |
| help="CPU reference (default) or experimental Apple GPU inference", | |
| ) | |
| commands = parser.add_subparsers(dest="command", required=True) | |
| commands.add_parser( | |
| "download-model", help="Download the pinned local snapshot; network required once" | |
| ) | |
| probe = commands.add_parser("probe") | |
| probe.add_argument("--fixtures", default="data/fixtures/playground-probes.json") | |
| probe.add_argument("--output", default="reports/local-probes.jsonl") | |
| probe.add_argument("--direct", action="store_true") | |
| sim = commands.add_parser("simulate") | |
| sim.add_argument( | |
| "--policy", choices=["rules", "rules-no-text", "hold", "hybrid", "direct"], default="rules" | |
| ) | |
| sim.add_argument("--scenario", default="low-pressure") | |
| sim.add_argument("--seed", type=int, default=42) | |
| sim.add_argument("--recipe", default=None) | |
| sim.add_argument("--output", default="reports/simulation.json") | |
| evaluate = commands.add_parser("evaluate") | |
| evaluate.add_argument("--config", default="configs/evaluation.yaml") | |
| evaluate.add_argument( | |
| "--split", choices=["training", "development", "final", "ood"], default="final" | |
| ) | |
| evaluate.add_argument("--condition", default="primary") | |
| evaluate.add_argument("--policies", nargs="+") | |
| evaluate.add_argument("--limit", type=int) | |
| evaluate.add_argument("--output") | |
| app = commands.add_parser("app") | |
| app.add_argument("--port", type=int, default=7860) | |
| args = parser.parse_args() | |
| os.environ["SEALCELL_DEVICE"] = args.device | |
| if args.command == "download-model": | |
| import runpy | |
| runpy.run_path(str(ROOT / "scripts/download_model.py"), run_name="__main__") | |
| elif args.command == "probe": | |
| from .evaluation import fixture_benchmark | |
| from .model import get_model | |
| model = get_model() | |
| Path(args.output).parent.mkdir(parents=True, exist_ok=True) | |
| results = fixture_benchmark(model, args.fixtures, args.output, args.direct) | |
| Path(args.output + ".metadata.json").write_text(json.dumps(model.metadata, indent=2) + "\n") | |
| print( | |
| json.dumps( | |
| { | |
| "output": args.output, | |
| "cases": len(results), | |
| "errors": sum(bool(r["error"]) for r in results), | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| if any(r["error"] for r in results): | |
| raise SystemExit(1) | |
| elif args.command == "simulate": | |
| from .evaluation import episode_metrics, manifest | |
| from .policies import policy | |
| from .simulator import Simulator | |
| from .supervisor import Supervisor | |
| runner = policy(args.policy) | |
| supervisor = Supervisor(Simulator(args.scenario, args.seed, args.recipe), runner).run() | |
| metrics = episode_metrics(supervisor) | |
| result = { | |
| "manifest": manifest(vars(args), getattr(runner, "model", None)), | |
| "metrics": metrics, | |
| "trace": supervisor.trace, | |
| } | |
| Path(args.output).parent.mkdir(parents=True, exist_ok=True) | |
| Path(args.output).write_text(json.dumps(result, indent=2) + "\n") | |
| print(json.dumps(metrics, indent=2)) | |
| elif args.command == "evaluate": | |
| from .evaluation import evaluate | |
| output, _ = evaluate( | |
| args.config, args.split, args.condition, args.policies, args.limit, args.output | |
| ) | |
| print(f"Report: {output / 'report.md'}") | |
| else: | |
| from .app import build_app | |
| build_app(device=args.device).queue().launch( | |
| server_name="127.0.0.1", server_port=args.port, share=False, show_error=True | |
| ) | |
| if __name__ == "__main__": | |
| main() | |