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

Function turn_ui_trees

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

Source from the content-addressed store, hash-verified

188 return result
189
190def turn_ui_trees(action_data):
191 accessibility_tree = action_data['ui_trees']
192 bounds_pattern = r'bounds_in_screen \{([^}]+)\}'
193 bounds_matches = list(re.finditer(bounds_pattern, accessibility_tree))
194 ui_trees = []
195 for i, match in enumerate(bounds_matches, 1):
196 bounds_content = match.group(1)
197 bounds_dict = {}
198 for item in bounds_content.strip().split('\n'):
199 item = item.strip()
200 if item:
201 key, value = item.split(': ')
202 bounds_dict[key] = int(value)
203 y_top_left = bounds_dict.get('top',0)
204 x_top_left = bounds_dict.get('left',0)
205 y_bottom_right = bounds_dict.get('bottom',0)
206 x_bottom_right = bounds_dict.get('right',0)
207 height = y_bottom_right - y_top_left
208 width=x_bottom_right - x_top_left
209 y_top_left_norm = y_top_left / action_data['screenshot_height']
210 x_top_left_norm = x_top_left / action_data['screenshot_width']
211 height_norm = height / action_data['screenshot_height']
212 width_norm = width / action_data['screenshot_width']
213 ui_trees.append([y_top_left_norm, x_top_left_norm, height_norm, width_norm])
214 return ui_trees
215
216def transform_action_data_and_build_test_data(action_data):
217 turn_action = transform_action_data(action_data)

Calls

no outgoing calls

Tested by

no test coverage detected