Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import sys | |
| REPO_ROOT = Path(__file__).resolve().parents[1] | |
| if str(REPO_ROOT) not in sys.path: | |
| sys.path.insert(0, str(REPO_ROOT)) | |
| from app_kit.lora_adapter import load_voice_journal_adapter | |
| DEFAULT_TRANSCRIPT = ( | |
| 'Caregiver says the patient took medication after a short walk, is resting comfortably, ' | |
| 'and has less shortness of breath than yesterday.' | |
| ) | |
| DEFAULT_TAGS = [ | |
| 'meds:medication', | |
| 'activity:walking', | |
| 'symptoms:shortness_of_breath', | |
| 'care:family', | |
| 'mood:calm', | |
| ] | |
| def _resolve(repo_root: Path, value: str) -> Path: | |
| path = Path(value).expanduser() | |
| if not path.is_absolute(): | |
| path = (repo_root / path).resolve() | |
| return path | |
| def main(argv: list[str] | None = None) -> int: | |
| parser = argparse.ArgumentParser(description='Verify that the bundled P2 adapter loads and ranks tags.') | |
| parser.add_argument( | |
| '--adapter', | |
| default='models/lora/p2_voice_journal_adapter.json', | |
| help='Path to the adapter JSON (relative to repo root by default).', | |
| ) | |
| parser.add_argument( | |
| '--transcript', | |
| default=DEFAULT_TRANSCRIPT, | |
| help='Transcript to score with the adapter.', | |
| ) | |
| parser.add_argument( | |
| '--tags', | |
| nargs='*', | |
| default=DEFAULT_TAGS, | |
| help='Candidate tags to rank. Defaults to a small P2 care-circle set.', | |
| ) | |
| args = parser.parse_args(argv) | |
| adapter_path = _resolve(REPO_ROOT, args.adapter) | |
| adapter = load_voice_journal_adapter(adapter_path) | |
| if adapter is None: | |
| raise SystemExit(f'Adapter not found at {adapter_path}') | |
| prioritized = adapter.prioritize_tags(args.tags, transcript=args.transcript) | |
| scores = adapter.score_tags(args.transcript, prioritized) | |
| payload = { | |
| 'adapter_name': adapter.adapter_name, | |
| 'adapter_type': adapter.adapter_type, | |
| 'loaded_from': str(adapter.loaded_from), | |
| 'has_scoring_state': bool(adapter.scoring_state), | |
| 'candidate_tags': args.tags, | |
| 'prioritized_tags': prioritized, | |
| 'scores': scores, | |
| } | |
| print(json.dumps(payload, indent=2, ensure_ascii=False, sort_keys=True)) | |
| return 0 | |
| if __name__ == '__main__': | |
| raise SystemExit(main()) | |