Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| from ML_Pipeline.steering.music_steering_spec import MusicSteeringSpec | |
| def extract_think_payload(raw_text: str) -> dict: | |
| start_token = "<|think|>" | |
| end_token = "</|think|>" | |
| start = raw_text.find(start_token) | |
| end = raw_text.find(end_token) | |
| if start == -1 or end == -1 or end <= start: | |
| raise ValueError("Missing <|think|> payload block.") | |
| payload = raw_text[start + len(start_token):end].strip() | |
| return json.loads(payload) | |
| def main() -> int: | |
| raw_text = """ | |
| Prelude | |
| <|think|> | |
| { | |
| "schema_version": "1.1", | |
| "emotion": {"energy": 0.82, "valence": 0.38, "tension": 0.71}, | |
| "rhythm": {"tempo_bpm": 132.0, "syncopation": 0.44, "density": 0.67}, | |
| "style_tags": ["dark-synth", "industrial", "cinematic"], | |
| "notes": ["bridge-build", "dummy-payload"] | |
| } | |
| </|think|> | |
| Postlude | |
| """.strip() | |
| payload = extract_think_payload(raw_text) | |
| steering = MusicSteeringSpec.from_dict(payload) | |
| report = { | |
| "status": "PASS", | |
| "schema_version": payload.get("schema_version", "missing"), | |
| "parsed": steering.to_dict(), | |
| } | |
| print(json.dumps(report, indent=2, sort_keys=True)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |