Views
No views yet
pip install transformers
pip install qwen-vl-utils1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2from qwen_vl_utils import process_vision_info
3
4# Default: Load the model on the available device(s)
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 "OS-Copilot/OS-Atlas-Base-7B", torch_dtype="auto", device_map="auto"
7)
8processor = AutoProcessor.from_pretrained("OS-Copilot/OS-Atlas-Base-7B")
9
10messages = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "image",
16 "image": "./web_6f93090a-81f6-489e-bb35-1a2838b18c01.png",
17 },
18 {"type": "text", "text": "In this UI screenshot, what is the position of the element corresponding to the command \"switch language of current page\" (with bbox)?"},
19 ],
20 }
21]
22
23
24# Preparation for inference
25text = processor.apply_chat_template(
26 messages, tokenize=False, add_generation_prompt=True
27)
28image_inputs, video_inputs = process_vision_info(messages)
29inputs = processor(
30 text=[text],
31 images=image_inputs,
32 videos=video_inputs,
33 padding=True,
34 return_tensors="pt",
35)
36inputs = inputs.to("cuda")
37
38# Inference: Generation of the output
39generated_ids = model.generate(**inputs, max_new_tokens=128)
40
41generated_ids_trimmed = [
42 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
43]
44
45output_text = processor.batch_decode(
46 generated_ids_trimmed, skip_special_tokens=False, clean_up_tokenization_spaces=False
47)
48print(output_text)
49# <|object_ref_start|>language switch<|object_ref_end|><|box_start|>(576,12),(592,42)<|box_end|><|im_end|>1@article{wu2024atlas,
2 title={OS-ATLAS: A Foundation Action Model for Generalist GUI Agents},
3 author={Wu, Zhiyong and Wu, Zhenyu and Xu, Fangzhi and Wang, Yian and Sun, Qiushi and Jia, Chengyou and Cheng, Kanzhi and Ding, Zichen and Chen, Liheng and Liang, Paul Pu and others},
4 journal={arXiv preprint arXiv:2410.23218},
5 year={2024}
6 }