支持私有化部署
AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


16.3K star! 微软开源AI Agent神器 OmniParser,让AI成为你的电脑操作专家

发布日期:2025-02-23 11:50:55 浏览次数: 2403 作者:字节笔记本
推荐语

微软开源AI神器OmniParser,让AI成为你的电脑操作专家,GitHub星标超16.3K!
核心内容:
1. OmniParser核心能力:将UI屏幕截图转换为结构化格式,精准理解和操作界面元素
2. V2版本性能提升:A100上0.6秒/帧,RTX 4090上0.8秒,平均准确率达39.6%
3. 环境搭建与实际应用:从克隆项目到创建Python环境,再到安装核心依赖和下载模型

杨芳贤
53A创始人/腾讯云(TVP)最具价值专家

微软官方发布并开源了OmniParser V2

gradio_demo.py · nisten/OmniParser at main

OmniParser可以将任何大语言模型(LLM)变成能够使用计算机的AI助手!项目已在GitHub上收获超过16.3k星标。

今天就带大家完整体验下这个神器,从环境搭建到实际应用。

下面的视频演示了如何使用OmniParser AI Agent自动化的发布X 帖子:

OmniParser核心能力

OmniParser就像是给AI装上了一双"慧眼"。它能将UI屏幕截图转换为结构化的格式,让AI精准理解和操作界面上的每个元素。

3b2a7230-20e1-4e14-a0f4-d73a89dac91e.png

V2版本性能更强:在A100上处理速度达到0.6秒/帧,在RTX 4090上也只需0.8秒。

在ScreenSpot Pro基准测试中更是达到了39.6%的平均准确率。

d5e89124-982a-489a-bbb3-57a9e1747b90.png

支持主流大模型,包括OpenAI (GPT-4V)、DeepSeek (R1)、Claude 3.5 Sonnet、Qwen (2.5VL)和Anthropic Computer Use。

通过全新的OmniTool,甚至可以直接控制Windows 11虚拟机!

环境准备

首先克隆项目到本地:

git clone https://github.com/microsoft/OmniParser.gitcd OmniParser

创建并激活Python环境:

conda create -n "omni" python==3.12
conda activate omni

安装核心依赖:

pip install --upgrade huggingface_hub
pip install gradio==4.14.0
pip install httpx==0.26.0
pip install httpcore==1.0.2
pip install anyio==4.2.0
pip install -r requirements.txt

下载模型文件

创建一个download_models.py脚本:

import osfrom huggingface_hub import hf_hub_downloadfrom pathlib import Pathdef download_omniparser_models():"""下载OmniParser V2的模型文件"""try:
base_path = Path("weights")
base_path.mkdir(exist_ok=True)

files = ["icon_detect/train_args.yaml","icon_detect/model.pt","icon_detect/model.yaml","icon_caption/config.json","icon_caption/generation_config.json","icon_caption/model.safetensors"]print("开始下载模型文件...")for file in files:print(f"正在下载: {file}")
hf_hub_download(
repo_id="microsoft/OmniParser-v2.0",
filename=file,
local_dir=base_path
)

icon_caption_path = base_path / "icon_caption"icon_caption_florence_path = base_path / "icon_caption_florence"if icon_caption_path.exists():if icon_caption_florence_path.exists():import shutil
shutil.rmtree(icon_caption_florence_path)
icon_caption_path.rename(icon_caption_florence_path)print("\n所有文件下载完成!")except Exception as e:print(f"\n下载过程中出现错误: {str(e)}")print("请检查网络连接并重试")if __name__ == "__main__":
download_omniparser_models()

在本地运行 Demo

python gradio_demo.py

运行后,打开浏览器访问本地服务(通常是 http://127.0.0.1:7860)。

上传任意界面截图后等待短暂处理(一般不超过1秒),就能看到详细的解析结果,包括可交互区域标注和功能描述。

效果如同下面这样,输入一张图片:

3da5ed98-4387-43ac-8ffc-3b8503d25f3b.png

输出图标标记的结果:
f2fdbb32-c162-4545-9e7a-f60370243d92.png

结构化的 JSON,这里包含了元素的内容识别和具体的坐标值:

38ae1703-ffa3-46ab-aa20-fd298ee7ba5e.png

有了这些具体的结构化识别结果后,那么想象空间就可以无限大了!

跨平台自动化实战案例

这里我们将实现一个跨平台的自动化操作方案:在服务器上部署OmniParser服务,然后通过macOS客户端实现自动化操作。

服务端部署:

from fastapi import FastAPI, UploadFilefrom PIL import Imageimport ioimport uvicorn

app = FastAPI()@app.post("/analyze")async def analyze_screen(image: UploadFile):# 读取上传的图片image_data = await image.read()
image = Image.open(io.BytesIO(image_data))# 使用OmniParser处理图片# 这里添加OmniParser的处理逻辑return {"elements": [...]}# 返回识别到的元素信息if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

客户端实现(macOS):

import pyautoguiimport requestsfrom PIL import ImageGrabdef capture_screen():"""获取屏幕截图"""screenshot = ImageGrab.grab()return screenshotdef convert_coordinates(omni_coords):"""转换OmniParser坐标到PyAutoGUI坐标"""# 根据实际情况调整坐标转换逻辑return omni_coordsdef click_element(coords):"""执行点击操作"""pyautogui.click(coords[0], coords[1])def main():# 获取屏幕截图screenshot = capture_screen()# 发送到OmniParser服务files = {'image': ('screenshot.png', screenshot)}
response = requests.post('http://ubuntu-server:8000/analyze', files=files)# 处理返回结果elements = response.json()['elements']# 执行自动化操作for element in elements:
coords = convert_coordinates(element['coords'])
click_element(coords)if __name__ == "__main__":
main()

说明如下:

  • 服务端负责图像解析:部署在服务端的OmniParser服务专门处理图像识别任务
  • 客户端执行操作:macOS上的脚本负责截图、发送请求和执行实际的鼠标操作
  • 跨平台协作:通过HTTP API实现两端的无缝配合

在这个基础框架,我们可以进一步扩展:

  • 接入GPT-4V等大模型,实现通过自然语言控制
  • 添加更多自动化操作,如键盘输入、拖拽等
  • 实现操作录制和回放功能
  • 添加错误处理和重试机制


53AI,企业落地大模型首选服务商

产品:场景落地咨询+大模型应用平台+行业解决方案

承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

添加专属顾问

回到顶部

加载中...

扫码咨询