Upload v2/cli.py with huggingface_hub
Browse files
v2/cli.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import random
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
from .config import get_preset
|
| 9 |
+
from .workflow import UnifiedWorkflow
|
| 10 |
+
from .check import check_model
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def build_parser() -> argparse.ArgumentParser:
|
| 14 |
+
p = argparse.ArgumentParser(description="MeshForge V2 unified pipeline runner")
|
| 15 |
+
|
| 16 |
+
subparsers = p.add_subparsers(dest="command", help="Command to run")
|
| 17 |
+
|
| 18 |
+
# Pipeline command (default)
|
| 19 |
+
pipeline_parser = subparsers.add_parser("run", help="Run the unified pipeline")
|
| 20 |
+
pipeline_parser.add_argument("--image", required=True, help="Path to reference portrait image")
|
| 21 |
+
pipeline_parser.add_argument("--output-dir", required=True, help="Directory for job outputs")
|
| 22 |
+
pipeline_parser.add_argument(
|
| 23 |
+
"--preset", default="quality", choices=["preview", "quality", "cinematic"]
|
| 24 |
+
)
|
| 25 |
+
pipeline_parser.add_argument("--seed", type=int, default=None)
|
| 26 |
+
pipeline_parser.add_argument("--tex-seed", type=int, default=None)
|
| 27 |
+
pipeline_parser.add_argument("--export-fbx", action="store_true")
|
| 28 |
+
|
| 29 |
+
# Check command
|
| 30 |
+
check_parser = subparsers.add_parser("check", help="Validate a model for pshuman rendering")
|
| 31 |
+
check_parser.add_argument("model", help="Path to GLB model file")
|
| 32 |
+
check_parser.add_argument(
|
| 33 |
+
"--model-type",
|
| 34 |
+
choices=["head", "body", "auto"],
|
| 35 |
+
default="auto",
|
| 36 |
+
help="Model type (auto-detected from filename if not specified)"
|
| 37 |
+
)
|
| 38 |
+
check_parser.add_argument(
|
| 39 |
+
"--json",
|
| 40 |
+
action="store_true",
|
| 41 |
+
help="Output results as JSON"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Legacy support: if --image and --output-dir are provided without a command
|
| 45 |
+
p.add_argument("--image", help=argparse.SUPPRESS)
|
| 46 |
+
p.add_argument("--output-dir", help=argparse.SUPPRESS)
|
| 47 |
+
p.add_argument(
|
| 48 |
+
"--preset", default="quality", choices=["preview", "quality", "cinematic"],
|
| 49 |
+
help=argparse.SUPPRESS
|
| 50 |
+
)
|
| 51 |
+
p.add_argument("--seed", type=int, default=None, help=argparse.SUPPRESS)
|
| 52 |
+
p.add_argument("--tex-seed", type=int, default=None, help=argparse.SUPPRESS)
|
| 53 |
+
p.add_argument("--export-fbx", action="store_true", help=argparse.SUPPRESS)
|
| 54 |
+
|
| 55 |
+
return p
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def run_pipeline(args) -> int:
|
| 59 |
+
cfg = get_preset(args.preset)
|
| 60 |
+
if args.export_fbx:
|
| 61 |
+
cfg = type(cfg)(**{**cfg.__dict__, "export_fbx": True})
|
| 62 |
+
|
| 63 |
+
seed = args.seed if args.seed is not None else random.randint(0, 2**31 - 1)
|
| 64 |
+
tex_seed = (
|
| 65 |
+
args.tex_seed if args.tex_seed is not None else random.randint(0, 2**31 - 1)
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
wf = UnifiedWorkflow(
|
| 69 |
+
config=cfg,
|
| 70 |
+
output_dir=Path(args.output_dir),
|
| 71 |
+
seed=seed,
|
| 72 |
+
tex_seed=tex_seed,
|
| 73 |
+
)
|
| 74 |
+
result = wf.run(Path(args.image))
|
| 75 |
+
|
| 76 |
+
print(f"status={result['status']}")
|
| 77 |
+
print(f"manifest={Path(args.output_dir) / 'manifest.json'}")
|
| 78 |
+
if result["status"] != "completed":
|
| 79 |
+
print(result.get("error", {}).get("message", "unknown error"))
|
| 80 |
+
return 1
|
| 81 |
+
return 0
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def run_check(args) -> int:
|
| 85 |
+
result = check_model(args.model, args.model_type)
|
| 86 |
+
|
| 87 |
+
if args.json:
|
| 88 |
+
print(json.dumps(result, indent=2))
|
| 89 |
+
else:
|
| 90 |
+
if result["status"] != "ok":
|
| 91 |
+
print(f"Error: {result['message']}")
|
| 92 |
+
return 1
|
| 93 |
+
|
| 94 |
+
model_type = "body" if any(r.get("location") for r in result.get("results", [])) else "head"
|
| 95 |
+
print(f"✓ Model validation passed ({model_type})")
|
| 96 |
+
|
| 97 |
+
if model_type == "body":
|
| 98 |
+
print(f"\nAnatomy checks (Y range: {result['y_range'][0]:.3f} to {result['y_range'][1]:.3f}):")
|
| 99 |
+
for r in result["results"]:
|
| 100 |
+
print(f" {r['location']:6s} (frac={r['fraction']:.2f}): "
|
| 101 |
+
f"x_mean={r['x_mean']:7.3f} x_std={r['x_std']:6.3f} "
|
| 102 |
+
f"z_mean={r['z_mean']:7.3f} z_std={r['z_std']:6.3f} "
|
| 103 |
+
f"n={r['points']}")
|
| 104 |
+
else:
|
| 105 |
+
for r in result["results"]:
|
| 106 |
+
print(f" {r['mesh']}: centroid={r['centroid']}, "
|
| 107 |
+
f"y_range=[{r['y_range'][0]:.3f}, {r['y_range'][1]:.3f}]")
|
| 108 |
+
|
| 109 |
+
return 0
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def main() -> int:
|
| 113 |
+
args = build_parser().parse_args()
|
| 114 |
+
|
| 115 |
+
# Legacy support: if --image and --output-dir provided, treat as pipeline run
|
| 116 |
+
if args.image and args.output_dir and not args.command:
|
| 117 |
+
args.command = "run"
|
| 118 |
+
elif not args.command:
|
| 119 |
+
build_parser().print_help()
|
| 120 |
+
return 1
|
| 121 |
+
|
| 122 |
+
if args.command == "run":
|
| 123 |
+
return run_pipeline(args)
|
| 124 |
+
elif args.command == "check":
|
| 125 |
+
return run_check(args)
|
| 126 |
+
|
| 127 |
+
return 0
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
raise SystemExit(main())
|