File size: 1,162 Bytes
bfee871
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Run Mixed-Messenger's audience predictor on Apple silicon."""
from pathlib import Path
import argparse,json,sys
from huggingface_hub import snapshot_download
from mixed_model import MixedModel

p=argparse.ArgumentParser(description=__doc__)
p.add_argument('topic',help='Topic whose Mixed Messages audience distribution to estimate')
p.add_argument('--model-dir',default=str(Path(__file__).resolve().parent))
p.add_argument('--base-path',help='Optional local pinned MLX Qwen base; otherwise download/cache it')
p.add_argument('--show-metrics',action='store_true')
a=p.parse_args();folder=Path(a.model_dir)
config=json.loads((folder/'model.json').read_text());prompt=json.loads((folder/'prompt.json').read_text())
base=a.base_path or snapshot_download(config['base_repository'],revision=config['base_revision'])
messages=[{'role':'system','content':prompt['system']},{'role':'user','content':'WORD: '+json.dumps(a.topic,ensure_ascii=False)+'\n\n'+prompt['instructions']}]
model=MixedModel(folder,base);prob,metrics=model.predict(messages)
print(json.dumps(prob,indent=2,ensure_ascii=False))
if a.show_metrics:print(json.dumps(metrics,indent=2),file=sys.stderr)