Views
No views yet
1pip install -U vllm
2vllm serve GUI-Libra/GUI-Libra-4B --port 8000 --api-key token-abc123http://localhost:8000/v1api_key here must match --api-key.pip install -U openaiminimal_infer.py:1import base64
2from openai import OpenAI
3
4MODEL = "GUI-Libra/GUI-Libra-7B"
5client = OpenAI(base_url="http://localhost:8000/v1", api_key="token-abc123")
6
7def b64_image(path: str) -> str:
8 with open(path, "rb") as f:
9 return base64.b64encode(f.read()).decode("utf-8")
10
11# 1) Your screenshot path
12img_b64 = b64_image("screen.png")
13
14system_prompt = """You are a GUI agent. You are given a task and a screenshot of the screen. You need to choose actions from the the following list:
15action_type: Click, action_target: Element description, value: None, point_2d: [x, y]
16 ## Explanation: Tap or click a specific UI element and provide its coordinates
17
18action_type: Select, action_target: Element description, value: Value to select, point_2d: [x, y] or None
19 ## Explanation: Select an item from a list or dropdown menu
20
21action_type: Write, action_target: Element description or None, value: Text to enter, point_2d: [x, y] or None
22 ## Explanation: Enter text into a specific input field or at the current focus if coordinate is None
23
24action_type: KeyboardPress, action_target: None, value: Key name (e.g., "enter"), point_2d: None
25 ## Explanation: Press a specified key on the keyboard
26
27action_type: Scroll, action_target: None, value: "up" | "down" | "left" | "right", point_2d: None
28 ## Explanation: Scroll a view or container in the specified direction
29"""
30
31# 2) Your prompt (instruction + desired output format)
32
33task_desc = 'Go to Amazon.com and buy a math book'
34prev_txt = ''
35question_description = '''Please generate the next move according to the UI screenshot {}, instruction and previous actions.\n\nInstruction: {}\n\nInteraction History: {}\n'''
36img_size_string = '(original image size {}x{})'.format(img_size[0], img_size[1])
37query = question_description.format(img_size_string, task_desc, prev_txt)
38
39query = query + '\n' + '''The response should be structured in the following format:
40<think>Your step-by-step thought process here...</think>
41<answer>
42{
43 "action_type": "the type of action to perform, e.g., Click, Write, Scroll, Answer, etc. Please follow the system prompt for available actions.",
44 "action_target": "the description of the target of the action, such as the color, text, or position on the screen of the UI element to interact with",
45 "value": "the input text or direction ('up', 'down', 'left', 'right') for the 'scroll' action, if applicable; otherwise, use 'None'",
46 "point_2d": [x, y] # the coordinates on the screen where the action is to be performed; if not applicable, use [-100, -100]
47}
48</answer>'''
49
50resp = client.chat.completions.create(
51 model=MODEL,
52 messages=[
53 {"role": "system", "content": "You are a helpful GUI agent."},
54 {"role": "user", "content": [
55 {"type": "image_url",
56 "image_url": {"url": f"data:image/png;base64,{img_b64}", "detail": "high"}},
57 {"type": "text", "text": prompt},
58 ]},
59 ],
60 temperature=0.0,
61 max_completion_tokens=1024,
62)
63
64print(resp.choices[0].message.content)python minimal_infer.pyscreen.png with your own screenshot file.8000.