1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_name = "Qwen/WebWorld-8B" # or WebWorld-14B, WebWorld-32B
5tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 device_map="auto",
9 torch_dtype=torch.bfloat16,
10 trust_remote_code=True,
11).eval()
12
13system_prompt = (
14 "You are a web world model. I will provide you with an initial page state "
15 "and a sequence of actions. For each action, predict the resulting page state.\n"
16 "Strictly maintain the original format. Output only the full page state "
17 "without explanations, code, or truncation."
18)
19
20current_state = """RootWebArea 'Global Start - Your Daily Portal', focused
21\t[1] banner 'Top Header', visible
22\t\t[2] link 'Set as Homepage', clickable, visible
23\t\t[3] link 'Feedback', clickable, visible
24\t\t[5] region 'Weather Widget', visible
25\t\t\tStaticText 'New York, USA'
26\t\t\t[6] image 'Sunny', visible
27\t\t\tStaticText '24°C'
28\t\t[8] link 'Sign In', clickable, visible
29\t[10] region 'Search Area', visible
30\t\t[11] image 'Global Start Logo', visible
31\t\tStaticText 'Search the entire web'
32\t\t[12] tablist 'Search Engine Selector', orientation='horizontal'
33\t\t\t[13] tab 'Google', selected=True, clickable
34\t\t\t[14] tab 'Bing', selected=False, clickable
35\t\t\t[15] tab 'DuckDuckGo', selected=False, clickable
36\t\t[18] combobox 'Web Search', clickable, visible, autocomplete='both', expanded=False
37\t\t\t[19] textbox 'Type keywords or URL...', clickable, visible, editable, value=''
38\t\t[20] button 'Search', clickable, visible
39\t[30] navigation 'Category Bar', visible
40\t\t[31] link 'Home', clickable, selected=True
41\t\t[32] link 'News', clickable
42\t\t[33] link 'Video', clickable
43\t\t[34] link 'Shopping', clickable
44\t\t[35] link 'Social', clickable
45\t[50] main 'Site Directory', visible
46\t\t[51] region 'Top Recommended', visible
47\t\t\t[52] heading 'Most Popular', visible
48\t\t\t[53] list 'Top Sites Grid', visible
49\t\t\t\t[54] link 'Facebook', clickable
50\t\t\t\t[56] link 'YouTube', clickable
51\t\t\t\t[58] link 'Amazon', clickable
52\t\t\t\t[60] link 'Twitter / X', clickable
53\t\t\t\t[62] link 'Instagram', clickable
54\t\t\t\t[64] link 'Wikipedia', clickable
55\t\t\t\t[66] link 'Netflix', clickable
56\t\t\t\t[68] link 'LinkedIn', clickable
57\t\t[80] region 'News & Media', visible
58\t\t\t[81] heading 'Latest News', visible
59\t\t\t[82] link 'CNN', clickable
60\t\t\t[83] link 'BBC', clickable
61\t\t\t[84] link 'The Verge', clickable
62\t\t[90] region 'Shopping', visible
63\t\t\t[91] heading 'E-Commerce', visible
64\t\t\t[92] link 'eBay', clickable
65\t\t\t[93] link 'Walmart', clickable
66\t\t\t[94] link 'Best Buy', clickable
67\t[200] complementary 'Ads', visible
68\t\t[201] image 'Ad: Travel to Japan'
69\t\t[202] link 'Book Now', clickable
70\t[300] contentinfo 'Footer', visible
71\t\tStaticText '© 2026 Global Start Inc.'"""
72
73user_message = (
74 f"Initial Page State:\n{current_state}\n\n"
75 f"First Action: 'click([32])'\n\n"
76 f"Next Page State:"
77)
78
79messages = [
80 {"role": "system", "content": system_prompt},
81 {"role": "user", "content": user_message},
82]
83
84text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
85inputs = tokenizer(text, return_tensors="pt").to(model.device)
86
87with torch.no_grad():
88 outputs = model.generate(
89 **inputs,
90 max_new_tokens=4096,
91 do_sample=False,
92 )
93
94response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
95print(response)