🚀🚀🚀本篇笔记所对应的视频:🚀本地部署OmniParser v2.0与pyautogui真正实现自动化点击!支持macOS、Windows与Linux!轻松实现自动化操作电脑_哔哩哔哩_bilibili
OmniParser V2.0是微软开发的一款先进开源AI工具,旨在将图形用户界面(GUI)截图转换为结构化数据。这一功能增强了大型语言模型(LLMs)与屏幕上视觉元素的互动,能够实现更加智能的自动化和用户辅助。
OmniParser V2.0代表了AI视觉解析技术的重大进步,它不仅促进了用户与数字界面之间的更好互动,还在各类应用中增强了自动化能力。
主要特点
- 速度与效率:与其前版本相比,OmniParser V2.0显著减少了约60%的处理延迟,在高端GPU(如A100)上的平均处理时间为0.6秒,在4090型号上为0.8秒。
- 增强的准确性:该工具在检测交互元素方面的平均准确率为39.6%,相比早期版本有了显著提升。这一准确率通过使用精细调优的YOLOv8模型和扩展的训练数据集(涵盖各种UI组件)得以实现。
- 强大的输入/输出能力:OmniParser支持来自多个平台的截图,包括Windows和移动设备。它能够生成UI元素的结构化表示,详细描述可点击区域及其功能。
- 与LLM的无缝集成:该工具通过统一接口OmniTool与多个AI模型集成,如OpenAI的GPT-4o、DeepSeek R1、Qwen 2.5VL和Anthropic Sonnet。这种集成使得创建自动化测试工具和辅助技术解决方案成为可能。
应用领域
OmniParser V2.0有广泛的应用场景:
- UI自动化:通过让AI代理与GUI互动来自动化重复任务。
- 辅助技术解决方案:为残障用户提供结构化数据,帮助辅助技术的实现。
- 用户界面分析:根据从截图中提取的数据分析UI设计,提升可用性[2][4]。
🚀安装步骤
conda create -n "omni" python==3.12 -y && conda activate omni
git clone <https://github.com/microsoft/OmniParser.git>
cd OmniParser
pip install -r requirements.txt
# 下载V2模型权重
rm -rf weights/icon_detect weights/icon_caption weights/icon_caption_florence
for f in icon_detect/{train_args.yaml,model.pt,model.yaml} icon_caption/{config.json,generation_config.json,model.safetensors}; do
huggingface-cli download microsoft/OmniParser-v2.0 "$f" --local-dir weights
done
mv weights/icon_caption weights/icon_caption_florence
# 启动UI
python gradio_demo.py
# 服务端配置
cd ~/OmniParser
pip install fastapi uvicorn python-multipart pillow requests
nano main.py
python main.py
🚀pyautogui
# pip install pyautogui
from time import sleep
import pyautogui
import time
def bbox_to_coords(bbox, screen_width, screen_height):
"""将 bbox 坐标转换为屏幕坐标."""
xmin, ymin, xmax, ymax = bbox
x_center = int((xmin + xmax) / 2 * screen_width)
y_center = int((ymin + ymax) / 2 * screen_height)
return x_center, y_center
def click_bbox(bbox):
"""点击指定的 bbox."""
screen_width, screen_height = pyautogui.siz