返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

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

[复制链接]
链载Ai 显示全部楼层 发表于 2 小时前 |阅读模式 打印 上一主题 下一主题

微软官方发布并开源了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虚拟机!

环境准备

首先克隆项目到本地:

gitclonehttps://github.com/microsoft/OmniParser.gitcdOmniParser

创建并激活Python环境:

condacreate-n"omni"python==3.12
condaactivateomni

安装核心依赖:

pipinstall--upgradehuggingface_hub
pipinstallgradio==4.14.0
pipinstallhttpx==0.26.0
pipinstallhttpcore==1.0.2
pipinstallanyio==4.2.0
pipinstall-rrequirements.txt

下载模型文件

创建一个download_models.py脚本:

importosfromhuggingface_hubimporthf_hub_downloadfrompathlibimportPathdefdownload_omniparser_models():"""下载OmniParserV2的模型文件"""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("开始下载模型文件...")forfileinfiles: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"ificon_caption_path.exists():ificon_caption_florence_path.exists():importshutil
shutil.rmtree(icon_caption_florence_path)
icon_caption_path.rename(icon_caption_florence_path)print("\n所有文件下载完成!")exceptExceptionase:print(f"\n下载过程中出现错误:{str(e)}")print("请检查网络连接并重试")if__name__=="__main__":
download_omniparser_models()

在本地运行 Demo

pythongradio_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客户端实现自动化操作。

服务端部署:

fromfastapiimportFastAPI,UploadFilefromPILimportImageimportioimportuvicorn

app=FastAPI()@app.post("/analyze")asyncdefanalyze_screen(image:UploadFile):#读取上传的图片image_data=awaitimage.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):

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

说明如下:

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

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

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


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ