Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vyokky committed May 1, 2024
1 parent df6bf5c commit 5554406
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ufo/automator/app_apis/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from typing import Type

from ...utils import print_with_color
from ..basic import ReceiverFactory
from .basic import WinCOMReceiverBasic
from .word.wordclient import WordWinCOMReceiver
from ...utils import print_with_color


class COMReceiverFactory(ReceiverFactory):
Expand Down
7 changes: 4 additions & 3 deletions ufo/automator/puppeteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Licensed under the MIT License.

from collections import deque
from .ui_control.controller import ControlReceiver, UIControlReceiverFactory
from typing import Dict, List

from .app_apis.basic import WinCOMReceiverBasic
from .app_apis.factory import COMReceiverFactory
from .basic import ReceiverFactory, ReceiverBasic
from typing import Dict, List
from .basic import ReceiverBasic, ReceiverFactory
from .ui_control.controller import ControlReceiver, UIControlReceiverFactory


class AppPuppeteer():
Expand Down
26 changes: 9 additions & 17 deletions ufo/automator/ui_control/control_filter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from abc import abstractmethod
import heapq
from ...utils import LazyImport

import time
import re
import warnings

from abc import abstractmethod
from typing import Dict, List

warnings.filterwarnings("ignore")

Expand All @@ -34,9 +31,10 @@ def create_control_filter(control_filter_type: str, *args, **kwargs):
raise ValueError("Invalid retriever type: {}".format(control_filter_type))

@staticmethod
def append_filtered_annotation_dict(filtered_control_dict, control_dicts):
def inplace_append_filtered_annotation_dict(filtered_control_dict: Dict, control_dicts: Dict):
"""
Appends the given control_info to the filtered_control_dict if it is not already present.
For example, if the filtered_control_dict is empty, it will be updated with the control_info. The operation is performed in place.
Args:
filtered_control_dict (dict): The dictionary of filtered control information.
Expand All @@ -46,15 +44,9 @@ def append_filtered_annotation_dict(filtered_control_dict, control_dicts):
dict: The updated filtered_control_dict dictionary.
"""
if control_dicts:
if filtered_control_dict:
for label, control_info in control_dicts.items():
if label not in filtered_control_dict:
filtered_control_dict[label] = control_info
return filtered_control_dict
else:
return control_dicts

filtered_control_dict.update({k: v for k, v in control_dicts.items() if k not in filtered_control_dict})
return filtered_control_dict


@staticmethod
def get_plans(plan, topk_plan):
Expand Down Expand Up @@ -191,12 +183,12 @@ class TextControlFilter:
"""

@staticmethod
def control_filter(control_dicts, plans):
def control_filter(control_dicts:Dict, plans: List[str]) -> Dict:
"""
Filters control items based on keywords.
Args:
control_dicts (dict): A dictionary of control items to be filtered.
keywords (list): A list of keywords to filter the control items.
plans (list): A list of plans for the following steps.
"""
filtered_control_dict = {}

Expand All @@ -221,7 +213,7 @@ def control_filter_score(self, control_text, plans):
control_text (str): The text of the control item.
plans (list): The plan to be used for calculating the similarity.
Returns:
float: The score indicating the similarity between the control text and the keywords.
float: The score (0-1) indicating the similarity between the control text and the keywords.
"""
plan_embedding = self.get_embedding(plans)
control_text_embedding = self.get_embedding(control_text)
Expand Down
3 changes: 1 addition & 2 deletions ufo/automator/ui_control/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def draw_rectangles_controls(image, coordinate:tuple, label_text:str, botton_mar
"""
Draw a rectangle around the control and label it.
:param image: The image to draw on.
:param save_path: The path to save the screenshot.
:param coordinate: The coordinate of the control.
:param label_text: The text label of the control.
:param botton_margin: The margin of the button.
Expand All @@ -199,7 +198,7 @@ def draw_rectangles_controls(image, coordinate:tuple, label_text:str, botton_mar
:param font_color: The color of the font.
:param border_color: The color of the border.
:param button_color: The color of the button.
return: The image with the rectangle and label.
return: The image with the control rectangle and label.
"""
_ = ImageDraw.Draw(image)
font = ImageFont.truetype("arial.ttf", font_size)
Expand Down
6 changes: 3 additions & 3 deletions ufo/module/processors/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,19 @@ def get_filtered_annotation_dict(self, annotation_dict: dict) -> Dict[str, Type]
if 'text' in control_filter_type_lower:
model_text = self.control_filter_factory.create_control_filter('text')
filtered_text_dict = model_text.control_filter(annotation_dict, plans)
filtered_annotation_dict = self.control_filter_factory.append_filtered_annotation_dict(filtered_annotation_dict, filtered_text_dict)
filtered_annotation_dict = self.control_filter_factory.inplace_append_filtered_annotation_dict(filtered_annotation_dict, filtered_text_dict)

if 'semantic' in control_filter_type_lower:
model_semantic = self.control_filter_factory.create_control_filter('semantic', configs["CONTROL_FILTER_MODEL_SEMANTIC_NAME"])
filtered_semantic_dict = model_semantic.control_filter(annotation_dict, plans, configs["CONTROL_FILTER_TOP_K_SEMANTIC"])
filtered_annotation_dict = self.control_filter_factory.append_filtered_annotation_dict(filtered_annotation_dict, filtered_semantic_dict)
filtered_annotation_dict = self.control_filter_factory.inplace_append_filtered_annotation_dict(filtered_annotation_dict, filtered_semantic_dict)


if 'icon' in control_filter_type_lower:
model_icon = self.control_filter_factory.create_control_filter('icon', configs["CONTROL_FILTER_MODEL_ICON_NAME"])

cropped_icons_dict = self.photographer.get_cropped_icons_dict(self._app_window, annotation_dict)
filtered_icon_dict = model_icon.control_filter(annotation_dict, cropped_icons_dict, plans, configs["CONTROL_FILTER_TOP_K_ICON"])
filtered_annotation_dict = self.control_filter_factory.append_filtered_annotation_dict(filtered_annotation_dict, filtered_icon_dict)
filtered_annotation_dict = self.control_filter_factory.inplace_append_filtered_annotation_dict(filtered_annotation_dict, filtered_icon_dict)

return filtered_annotation_dict
3 changes: 1 addition & 2 deletions ufo/module/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from ..agent.agent import AgentFactory
from ..automator.ui_control.screenshot import PhotographerFacade
from ..config.config import Config

from . import interactor, round
from .state import StatusToStateMapper
from .basic import BaseSession
from .state import StatusToStateMapper

configs = Config.get_instance().config_data
BACKEND = configs["CONTROL_BACKEND"]
Expand Down

0 comments on commit 5554406

Please sign in to comment.