"""Arc Tagger quickstart. Run from the downloaded repo: python example.py [local dir or repo id, default: this dir] (the repo id is WhissleAI/arc-tagger)""" import json, os, sys, time HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE) import torch torch.set_num_threads(int(os.environ.get("ARCTAG_THREADS", "2"))) from arctag import ArcTagger tg = ArcTagger.from_pretrained(sys.argv[1] if len(sys.argv) > 1 else HERE) # 1) offline: plain text (utterances end after . ? !) out = tg.tag("Hi, thanks for calling Northwind Bank, this is Maria. My name is John Patel and my number is " "five five five, two one three, four four eight nine.", domain="talk") print("redacted:", out["redacted_text"]) for s in out["spans"]: print(f" span {s['tag']:<34} {s['text']!r} p={s['p']}") for u in out["utterances"]: print(f" utt [{u['start']}:{u['end']}] act={u['act']} intent={u['intent']} safety={u['safety']}") # 2) streaming: push ASR words as they arrive (interim -> revised final), endpoint at end of utterance st = tg.stream(domain="assistant") st.push_words(["set", "an", "alarm", "for"], final=False) # interim hypothesis up = st.push_words(["set", "an", "alarm", "for", "seven", "thirty."], revise_from=0, final=True) # final replaces words[0:] print("live spans:", [(s["tag"], s["text"]) for s in up["spans"]]) up = st.endpoint() print("utterance:", up["utterances"][0]["intent"], up["utterances"][0]["act"]) res = st.finalize() print("latency:", st.s.stats()) print(json.dumps({k: res[k] for k in ("meta", "spans", "events")}, indent=1)[:1500])