MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / transform_action_data

Function transform_action_data

eval/eval_data/process_ac.py:125–188  ·  view source on GitHub ↗
(action_data)

Source from the content-addressed store, hash-verified

123############################################################
124
125def transform_action_data(action_data):
126 action = json.loads(action_data['action'])
127 action_type = action['action_type']
128
129 result = {}
130 result['result_action_type'] = 2 #unused
131 result['result_action_text'] = ""
132 result['result_lift_yx'] = [-1.0,-1.0]
133 result['result_touch_yx'] = [-1.0,-1.0]
134 result['duration'] = None
135
136 if action_type in ['click', 'long_press', 'scroll']:
137 try:
138 start_x = (action['x'] / action_data['screenshot_width'])
139 start_y = (action['y'] / action_data['screenshot_height'])
140 except:
141 start_x = 0.5
142 start_y = 0.5
143 if action_type == 'click' or action_type == 'long_press':
144 end_x, end_y = start_x, start_y
145 elif action_type == 'scroll':
146 # Android control has reversed scroll directions
147 map_direction = {'left': 'right', 'right': 'left', 'up': 'down', 'down': 'up'}
148 direction = map_direction[action['direction']]
149 if direction == 'up':
150 end_x, end_y = start_x, max(0, start_y - 0.3)
151 elif direction == 'down':
152 end_x, end_y = start_x, min(1, start_y + 0.3)
153 elif direction == 'left':
154 end_x, end_y = max(0, start_x - 0.3), start_y
155 else: # right
156 end_x, end_y = min(1, start_x + 0.3), start_y
157
158 result['result_action_type'] = 4 # dual point
159 result['result_touch_yx'] = [start_y, start_x] # [y,x]
160 result['result_lift_yx'] = [end_y, end_x]
161
162 elif action_type == 'input_text':
163 # Type action
164 result['result_action_type'] = 3 #type
165 result['result_action_text'] = action['text']
166
167 elif action_type == 'navigate_home':
168 # Button press actions
169 result['result_action_type'] = 6 #home
170
171 elif action_type == 'navigate_back':
172 result['result_action_type'] = 5 #back
173 elif action_type == 'wait':
174 result['result_action_type'] = 1 #wait
175 elif action_type == 'long_press':
176 result['result_action_type'] = 0 #long_press
177 start_x = (action['x'] / action_data['screenshot_width'])
178 start_y = (action['y'] / action_data['screenshot_height'])
179 end_x = start_x
180 end_y = start_y
181 result['result_touch_yx'] = [start_y, start_x]
182 result['result_lift_yx'] = [end_y, end_x]

Calls

no outgoing calls

Tested by

no test coverage detected