emerging.systems / bqsm_assist /tokenizer_server.py
compunerd's picture
Port full dashboard engine: phoenix_dashboard + agent_core + hyper_vocab_memory + bqsm_assist
bdf5f4a verified
Raw History Blame Contribute Delete
903 Bytes
#!/usr/bin/env python3
"""Tokenizer server for Phoenix dashboard.
Runs as a subprocess, reads JSON from stdin, writes JSON to stdout.
Commands: {"cmd":"encode","text":"hello"} -> {"ids":[1,2,3]}
{"cmd":"decode","ids":[1,2,3]} -> {"text":"hello"}
"""
import sys, json
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("/home/compunerd/models/gemma4-tokenizer")
for line in sys.stdin:
try:
req = json.loads(line.strip())
if req.get("cmd") == "encode":
ids = tok.encode(req.get("text", ""))
print(json.dumps({"ids": ids}))
elif req.get("cmd") == "decode":
text = tok.decode(req.get("ids", []))
print(json.dumps({"text": text}))
else:
print(json.dumps({"error": "unknown cmd"}))
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.stdout.flush()