Compare commits
7 Commits
c2fb041285
...
main
Author | SHA1 | Date | |
---|---|---|---|
6b13586154 | |||
7192f4bc18 | |||
36cfeffe9c | |||
7f5296b2ef | |||
e5b3ea8b57 | |||
ff7c362cfe | |||
b035bee682 |
@@ -45,14 +45,15 @@ def perform_ocr(screenshot: bytes) -> list[dict]:
|
|||||||
for i in range(n):
|
for i in range(n):
|
||||||
text = data['text'][i]
|
text = data['text'][i]
|
||||||
if text and text.strip():
|
if text and text.strip():
|
||||||
|
# Fix the center-point calculation (add first, then divide)
|
||||||
results.append({
|
results.append({
|
||||||
'text': text,
|
'text': text,
|
||||||
'x': data['width'][i] + data['left'][i] // 2, # center x position
|
'x': data['left'][i] + data['width'][i] // 2,
|
||||||
'y': data['height'][i] + data['top'][i] // 2 # center y position
|
'y': data['top'][i] + data['height'][i] // 2
|
||||||
})
|
})
|
||||||
|
|
||||||
# check if debug is enabled
|
# check if debug is enabled
|
||||||
if logging.getLogger().isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
# take screenshot + put blue circle with x, y on screenshot for each component
|
# take screenshot + put blue circle with x, y on screenshot for each component
|
||||||
screenshot_with_circles = Image.open(io.BytesIO(screenshot))
|
screenshot_with_circles = Image.open(io.BytesIO(screenshot))
|
||||||
draw = ImageDraw.Draw(screenshot_with_circles)
|
draw = ImageDraw.Draw(screenshot_with_circles)
|
||||||
@@ -66,9 +67,9 @@ def perform_ocr(screenshot: bytes) -> list[dict]:
|
|||||||
# vertical line
|
# vertical line
|
||||||
draw.line((x, y - size, x, y + size), fill=color, width=width)
|
draw.line((x, y - size, x, y + size), fill=color, width=width)
|
||||||
screenshot_with_circles.save("screenshot_with_circles.png", format='PNG')
|
screenshot_with_circles.save("screenshot_with_circles.png", format='PNG')
|
||||||
# save in a file
|
# save in a file
|
||||||
logger.debug("Debug, saving ocr results screenshot with circles")
|
logger.debug("Debug, saving ocr results screenshot with circles")
|
||||||
screenshot_with_circles.save("ocr_results.png", format='PNG')
|
screenshot_with_circles.save("ocr_results.png", format='PNG')
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def screenshot_to_base64(screenshot: bytes) -> str:
|
def screenshot_to_base64(screenshot: bytes) -> str:
|
||||||
@@ -109,7 +110,7 @@ def wait(duration: float) -> None:
|
|||||||
def search_pc(query: str) -> None:
|
def search_pc(query: str) -> None:
|
||||||
"""Presses the Windows key."""
|
"""Presses the Windows key."""
|
||||||
pyautogui.hotkey('win')
|
pyautogui.hotkey('win')
|
||||||
wait(2)
|
wait(4)
|
||||||
press_keyboard(KeyboardInput(text=query))
|
press_keyboard(KeyboardInput(text=query))
|
||||||
|
|
||||||
def reprompt(nextsteps: str, processor) -> None:
|
def reprompt(nextsteps: str, processor) -> None:
|
||||||
|
@@ -111,12 +111,13 @@ class AIProcessor:
|
|||||||
try:
|
try:
|
||||||
ocr_results = ai.compute.perform_ocr(img_bytes)
|
ocr_results = ai.compute.perform_ocr(img_bytes)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
logger.debug("OCR failed: %s", e)
|
logger.debug("OCR failed: %s", e)
|
||||||
|
|
||||||
self.session.messages.append(
|
self.session.messages.append(
|
||||||
aic.Message(
|
aic.Message(
|
||||||
role="assistant",
|
role="assistant",
|
||||||
content=str(tool_calls),
|
content=str(((tc.function.name, tc.function.arguments) for tc in tool_calls)),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -134,7 +135,7 @@ class AIProcessor:
|
|||||||
output_text: str = response.choices[0].message.content # type: ignore
|
output_text: str = response.choices[0].message.content # type: ignore
|
||||||
outputs.append(output_text)
|
outputs.append(output_text)
|
||||||
self.session.messages.append(
|
self.session.messages.append(
|
||||||
aic.Message(role="assistant", content=output_text)
|
aic.Message(role="assistant", content="Executed: " + (str(*outputs)))
|
||||||
)
|
)
|
||||||
|
|
||||||
return [*outputs]
|
return [*outputs]
|
||||||
|
@@ -31,7 +31,7 @@ FUNCTIONS = [
|
|||||||
"click_type": {
|
"click_type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["left", "double_left", "middle", "right"],
|
"enum": ["left", "double_left", "middle", "right"],
|
||||||
"description": "The type of mouse click to perform. `double_left` is a double click."
|
"description": "The type of mouse click to perform. `double_left` is a double click, used to open apps or files."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["click_type", "x", "y"],
|
"required": ["click_type", "x", "y"],
|
||||||
|
Reference in New Issue
Block a user