Spaces:
Running on Zero
Running on Zero
| """Generate stable public sample traces for the mock MVP.""" | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| PROJECT_ROOT = Path(__file__).resolve().parents[1] | |
| if str(PROJECT_ROOT) not in sys.path: | |
| sys.path.insert(0, str(PROJECT_ROOT)) | |
| from src.examples import EXAMPLE_OBJECTS | |
| from src.pipeline import generate_object_diary | |
| DEFAULT_OUTPUT_DIR = Path("data/traces/samples") | |
| def generate_sample_traces(output_dir: Path = DEFAULT_OUTPUT_DIR) -> list[Path]: | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| written_paths: list[Path] = [] | |
| for index, example in enumerate(EXAMPLE_OBJECTS, start=1): | |
| description = example["description"] | |
| mode = example["mode"] | |
| result = generate_object_diary( | |
| image_path=None, | |
| description=description, | |
| mode=mode, | |
| save=False, | |
| trace_id=f"sample-{index:02d}", | |
| created_at=datetime(2026, 6, 5, 0, index, tzinfo=timezone.utc), | |
| ) | |
| filename = f"sample-{index:02d}-{_slug(example['label'])}.json" | |
| path = output_dir / filename | |
| path.write_text( | |
| json.dumps(result.trace.model_dump(mode="json"), ensure_ascii=False, indent=2), | |
| encoding="utf-8", | |
| ) | |
| written_paths.append(path) | |
| return written_paths | |
| def _slug(value: str) -> str: | |
| slug = value.split("/", maxsplit=1)[0].strip().lower() | |
| return "".join(char if char.isalnum() else "-" for char in slug).strip("-") | |
| if __name__ == "__main__": | |
| for generated_path in generate_sample_traces(): | |
| print(generated_path) | |