SeaWolf-AI commited on
Commit
2ff0108
Β·
verified Β·
1 Parent(s): d6b962e

Upload example_submission.py

Browse files
Files changed (1) hide show
  1. example_submission.py +133 -0
example_submission.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WM Bench β€” Example Submission Script
3
+ =====================================
4
+ Any world model can participate in WM Bench using this template.
5
+ No 3D environment needed β€” text input/output only.
6
+
7
+ Usage:
8
+ python example_submission.py --api_url YOUR_MODEL_API --api_key YOUR_KEY --model YOUR_MODEL_NAME
9
+ """
10
+
11
+ import json
12
+ import argparse
13
+ import requests
14
+ import time
15
+ from pathlib import Path
16
+
17
+ # ── μ„€μ • ────────────────────────────────────────────────────────
18
+ DATASET_PATH = Path(__file__).parent.parent / "data" / "wm_bench_dataset.json"
19
+
20
+ SYSTEM_PROMPT = """You are a world model. Given scene_context as JSON, respond in exactly 2 lines:
21
+ Line 1: PREDICT: left=<safe|danger>(<reason>), right=<safe|danger>(<reason>), fwd=<safe|danger>(<reason>), back=<safe|danger>(<reason>)
22
+ Line 2: MOTION: <describe the character's physical motion and emotional state in one sentence>
23
+ Respond ONLY these 2 lines. No explanation."""
24
+
25
+ # ── 메인 평가 ν•¨μˆ˜ ───────────────────────────────────────────────
26
+ def run_evaluation(api_url: str, api_key: str, model: str, output_path: str = "my_submission.json"):
27
+ """
28
+ WM Bench 평가λ₯Ό μ‹€ν–‰ν•˜κ³  제좜 νŒŒμΌμ„ μƒμ„±ν•©λ‹ˆλ‹€.
29
+
30
+ Parameters:
31
+ api_url: OpenAI ν˜Έν™˜ API URL (예: https://api.openai.com/v1/chat/completions)
32
+ api_key: API ν‚€
33
+ model: λͺ¨λΈ 이름
34
+ output_path: 제좜 파일 경둜
35
+ """
36
+ # 데이터셋 λ‘œλ“œ
37
+ with open(DATASET_PATH, "r", encoding="utf-8") as f:
38
+ dataset = json.load(f)
39
+
40
+ scenarios = dataset["scenarios"]
41
+ print(f"βœ… 데이터셋 λ‘œλ“œ: {len(scenarios)}개 μ‹œλ‚˜λ¦¬μ˜€")
42
+ print(f"πŸ€– λͺ¨λΈ: {model}")
43
+ print(f"πŸ”— API: {api_url}\n")
44
+
45
+ results = []
46
+ errors = 0
47
+
48
+ for i, scenario in enumerate(scenarios):
49
+ sc_id = scenario["id"]
50
+ cat = scenario["cat"]
51
+ scene = scenario["scene_context"]
52
+
53
+ # API 호좜
54
+ t0 = time.time()
55
+ response_text, latency_ms = call_api(api_url, api_key, model, scene)
56
+
57
+ if response_text is None:
58
+ errors += 1
59
+ print(f" ❌ {sc_id} ({cat}): API 였λ₯˜")
60
+ results.append({
61
+ "id": sc_id,
62
+ "cat": cat,
63
+ "response": None,
64
+ "latency_ms": latency_ms,
65
+ "error": True
66
+ })
67
+ else:
68
+ results.append({
69
+ "id": sc_id,
70
+ "cat": cat,
71
+ "response": response_text,
72
+ "latency_ms": round(latency_ms, 1),
73
+ "error": False
74
+ })
75
+
76
+ if (i + 1) % 10 == 0:
77
+ print(f" βœ“ {i+1}/100 μ™„λ£Œ ({cat})")
78
+
79
+ # 제좜 파일 생성
80
+ submission = {
81
+ "model": model,
82
+ "api_url": api_url,
83
+ "track": "A", # Text-Only Track
84
+ "submitted_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
85
+ "total_scenarios": len(scenarios),
86
+ "errors": errors,
87
+ "results": results
88
+ }
89
+
90
+ with open(output_path, "w", encoding="utf-8") as f:
91
+ json.dump(submission, f, ensure_ascii=False, indent=2)
92
+
93
+ print(f"\nβœ… 제좜 파일 생성: {output_path}")
94
+ print(f" 총 μ‹œλ‚˜λ¦¬μ˜€: {len(scenarios)}, 였λ₯˜: {errors}")
95
+ print(f"\nπŸ“€ λ‹€μŒ 단계: WM Bench Space에 제좜 파일 μ—…λ‘œλ“œ")
96
+ print(f" https://huggingface.co/spaces/FINAL-Bench/worldmodel-bench")
97
+ return output_path
98
+
99
+
100
+ def call_api(api_url: str, api_key: str, model: str, scene_context: dict):
101
+ """OpenAI ν˜Έν™˜ API 호좜"""
102
+ headers = {
103
+ "Content-Type": "application/json",
104
+ "Authorization": f"Bearer {api_key}"
105
+ }
106
+ payload = {
107
+ "model": model,
108
+ "max_tokens": 200,
109
+ "temperature": 0.0,
110
+ "messages": [
111
+ {"role": "system", "content": SYSTEM_PROMPT},
112
+ {"role": "user", "content": f"scene_context: {json.dumps(scene_context)}"}
113
+ ]
114
+ }
115
+ t0 = time.time()
116
+ try:
117
+ r = requests.post(api_url, headers=headers, json=payload, timeout=30)
118
+ r.raise_for_status()
119
+ text = r.json()["choices"][0]["message"]["content"]
120
+ return text, (time.time() - t0) * 1000
121
+ except Exception as e:
122
+ return None, (time.time() - t0) * 1000
123
+
124
+
125
+ if __name__ == "__main__":
126
+ parser = argparse.ArgumentParser(description="WM Bench Submission Script")
127
+ parser.add_argument("--api_url", required=True, help="OpenAI-compatible API URL")
128
+ parser.add_argument("--api_key", required=True, help="API Key")
129
+ parser.add_argument("--model", required=True, help="Model name")
130
+ parser.add_argument("--output", default="my_submission.json", help="Output file path")
131
+ args = parser.parse_args()
132
+
133
+ run_evaluation(args.api_url, args.api_key, args.model, args.output)