"""CPU inference example for davolu/emotion-s1. Inference only; no training. Usage: python example.py --model-dir /path/to/emotion-s1 python example.py # downloads davolu/emotion-s1 from the Hub """ import argparse import sys import time def main(): parser = argparse.ArgumentParser(description="Run Emotion-S1 on one example turn (CPU).") parser.add_argument("--model-dir", default=None, help="Local model directory. If omitted, snapshot_download('davolu/emotion-s1') is used.") parser.add_argument("--device", default="cpu") args = parser.parse_args() if args.model_dir: model_dir = args.model_dir else: from huggingface_hub import snapshot_download model_dir = snapshot_download("davolu/emotion-s1") sys.path.insert(0, model_dir) from emotion_s1_core import load_emotion_s1, ask model = load_emotion_s1(model_dir, device=args.device) questions = { "emotion": { "type": "choice", "question": "What is the user's emotion in this turn?", "options": ["anger", "disgust", "fear", "joy", "sadness", "surprise", "neutral"], }, "intensity": { "type": "score", "question": "How intense is the user's emotion on a 1 to 5 scale?", "scale": [1, 5], }, "frustrated": { "type": "noul", "question": "Is the user frustrated?", }, "needs_support": { "type": "noul", "question": "Does the user need emotional support?", }, } turn = "I've asked three times and it's STILL broken." context = [("Assistant", "Did that fix it?")] # Warm-up (first forward pass includes model load overhead already paid above) ask(model, turn, questions, context=context) t0 = time.perf_counter() out = ask(model, turn, questions, context=context) ms = (time.perf_counter() - t0) * 1000 for name, result in out.items(): print(f"{name}: {result}") print(f"latency_ms: {ms:.1f}") if __name__ == "__main__": main()