OmniParser

repository·master·Indexed 12 days ago

https://github.com/microsoft/omniparser

A framework for controlling Windows 11 environments using vision-language models. It includes OmniParser V2 for visual element detection, OmniBox (a Dockerized Windows VM), and a Gradio-based control interface. The system utilizes YOLO for object detection and caption models like florence2 or blip2 for semantic labeling and OCR to enable AI agents to interact with UI elements.

Tokens
3.9K
Snippets
11
Records
19
Agent score
98%

What's inside OmniParser

  1. Overview of OmniTool components

    master

    OmniTool is a system designed to control a Windows 11 VM using OmniParser and a vision model. It consists of three main components:

    1. omniparserserver: A FastAPI server running OmniParser V2, used for visual parsing.
    2. omnibox: A Windows 11 VM running inside a Docker container, providing the computer use API.
    3. gradio: A user interface to provide commands and monitor the reasoning and execution process on OmniBox.

    Deployment Recommendation: For optimal performance, run omnibox and gradio on a CPU machine, and run omniparserserver on a GPU server.

  2. Setup Gradio UI

    master

    The Gradio UI allows you to interact with the AI agent. Ensure your omniparserserver and omnibox are running before starting.

    1. Navigate to the gradio directory:
      cd OmniParser/omnitool/gradio
    2. Activate your conda environment:
      conda activate omni
    3. Start the Gradio server, specifying the URLs for the Windows host and the OmniParser server:
      python app.py --windows_host_url localhost:8006 --omniparser_server_url localhost:8000
    4. Open the URL provided in the terminal output, enter your API Key, and begin using the agent.
    python app.py --windows_host_url localhost:8006 --omniparser_server_url localhost:8000
  3. Set up evaluation for ScreenSpot Pro

    master

    To evaluate OmniParser on the ScreenSpot Pro (ss pro) benchmark, you can use the adapted evaluation scripts provided in this repository. This setup is designed to be compatible with the original ScreenSpot Pro official repository.

    Steps to use the adapted evaluation:

    1. Replace the model file: Take the script eval/ss_pro_gpt4o_omniv2.py from this repository and use it to replace the existing models/gpt4x.py file in the original ScreenSpot Pro repository. This script contains the specific prompts used for the OmniParser evaluation.
    2. Review results: Inference results for ScreenSpot Pro using the GPT4o + OmniParser v2 combination are available in eval/logs_sspro_omniv2.json.
    # Note: This guide describes a file replacement workflow in an external repository.
    # 1. Copy eval/ss_pro_gpt4o_omniv2.py
    # 2. Paste into [original ss pro repo]/models/gpt4x.py
  4. Setup omniparserserver

    master

    Follow these steps to set up the OmniParser V2 FastAPI server using Conda:

    1. Create and activate a Conda environment with Python 3.12:
      conda create -n "omni" python==3.12
      conda activate omni
    2. Install dependencies:
      pip install -r requirements.txt
    3. Download the required weights (Detector and Caption weights):
      huggingface-cli download microsoft/OmniParser-v2.0 icon_detect_v3/model.pt --revision refs/pr/37 --local-dir weights
      rm -rf weights/icon_caption weights/icon_caption_florence
      huggingface-cli download microsoft/OmniParser-v2.0 --local-dir weights --repo-type model --include "icon_caption/*"
      mv weights/icon_caption weights/icon_caption_florence
    4. Start the server:
      cd OmniParser/omnitool/omniparserserver
      python -m omniparserserver
    python -m omniparserserver
  5. Setup omnibox (Windows 11 VM in Docker)

    master

    OmniBox provides a Windows 11 environment via Docker. Note that this requires KVM and is best suited for Windows or Linux hosts.

    Prerequisites:

    • 30GB of free disk space.
    • Docker Desktop installed.
    • A Windows 11 Enterprise Evaluation (90-day trial, English, United States) ISO file from the Microsoft Evaluation Center.

    Installation Steps:

    1. Rename your downloaded ISO to custom.iso.
    2. Copy custom.iso to OmniParser/omnitool/omnibox/vm/win11iso.
    3. Navigate to the scripts directory:
      cd OmniParser/omnitool/omnibox/scripts
    4. Build and create the VM:
      ./manage_vm.sh create
      Note: This process takes 20-90 minutes. When finished, the terminal will display VM + server is up and running!.

    VM Management:

    • Start the VM: ./manage_vm.sh start
    • Stop the VM: ./manage_vm.sh stop
    • Delete the VM: ./manage_vm.sh delete (Note: You must also manually delete the OmniParser/omnitool/omnibox/vm/win11storage directory to fully clear the state).
    ./manage_vm.sh create
  6. Configure OmniTool via the Web UI

    master

    The Gradio interface allows you to adjust several parameters for the AI agent's behavior:

    • Model: Select from supported models including omniparser + gpt-4o, omniparser + o1, omniparser + R1, omniparser + qwen2.5vl, and Anthropic's claude-3-5-sonnet-20241022.
    • N most recent screenshots: A slider to control how many recent screenshots are sent to the model (0-10).
    • API Provider: Select the provider for your LLM (e.g., openai, anthropic, groq, dashscope, bedrock, vertex).
    • API Key: Enter the required API key for the selected provider.

    Note: Changing the Model may automatically update the available API Provider options and the required API Key placeholder.

  7. Run the OmniTool Gradio Web Application

    master

    The OmniTool interface is provided via a Gradio web application. You can launch it from the command line, specifying the URLs for the Windows host (where the VNC session is running) and the OmniParser server.

    To run the application, use the following command:

    python app.py --windows_host_url localhost:8006 --omniparser_server_url localhost:8000

    By default, the app launches on 127.0.0.1:7888.

  8. Initialize YOLO and Caption models

    master

    To use OmniParser, you need to initialize a YOLO model for object detection (SOM) and a caption model for semantic labeling. You can choose between two caption model types: fine-tuned blip2 or florence2.

    import torch
    from util.utils import get_yolo_model, get_caption_model_processor
    
    device = 'cuda' # or 'cpu'
    
    # Initialize the SOM (Set of Marks) model using YOLO
    som_model = get_yolo_model(device=device)
    
    # Initialize the caption model processor
    # Options for model_name include 'florence2'
    caption_model_processor = get_caption_model_processor(
        model_name="florence2", 
        model_name_or_path="weights/icon_caption_florence", 
        device=device
    )
  9. Troubleshoot: libpaddle: The specified module could not be found

    master

    The OmniParser OCR library (Paddle) requires the C++ Redistributable on Windows. If you encounter this error:

    1. Install the C++ Redistributable on your Windows host.
    2. Rerun the dependency installation:
      pip install -r requirements.txt
  10. Troubleshoot: Validation errors: Windows Host is not responding

    master

    If Gradio returns a 'Windows Host is not responding' error, the server inside the VM is likely unavailable.

    Diagnostic Steps:

    1. Verify the VM server status by running this command inside the container:
      docker exec -it omni-windows bash -c "curl http://localhost:5000/probe"
    2. If the VM is still in its initial setup phase, wait for the terminal window in the NoVNC viewer to disappear.

    Resolution Steps:

    1. Wait up to 10 minutes.
    2. Restart the VM:
      ./manage_vm.sh stop
      ./manage_vm.sh start
    3. If issues persist, delete the VM but keep the storage folder, then run create again:
      ./manage_vm.sh delete
      ./manage_vm.sh create
    4. Factory Reset: If all else fails, delete the VM, manually delete the vm/win11storage folder, and run ./manage_vm.sh create again.
  11. Configure the OmniBox Windows service via compose.yml

    master

    The windows service in compose.yml defines the environment for the Windows host used by OmniBox. You can customize the hardware resources and data persistence through environment variables and volume mappings.

    Environment Variables

    • RAM_SIZE: Specifies the amount of RAM allocated to the Windows instance (e.g., "8G").
    • CPU_CORES: Specifies the number of CPU cores allocated (e.g., "4").
    • DISK_SIZE: Specifies the disk size (e.g., "20G").

    Volume Mappings

    To customize the Windows installation or persist data, map local directories to the following container paths:

    • /custom.iso: The Windows ISO file (e.g., ./vm/win11iso/custom.iso).
    • /oem: OEM setup files/first boot configuration (e.g., ./vm/win11setup/firstboot).
    • /data: Setup scripts (e.g., ./vm/win11setup/setupscripts).
    • /storage: Persistent storage for the Windows instance (e.g., ./vm/win11storage).

    Network Access

    The service exposes port 8006 for Web Viewer access.

    services:
      windows:
        image: windows-local
        container_name: omni-windows
        privileged: true
        environment:
          RAM_SIZE: "8G"
          CPU_CORES: "4"
          DISK_SIZE: "20G"
        devices:
          - /dev/kvm
          - /dev/net/tun
        cap_add:
          - NET_ADMIN
        ports:
          - 8006:8006                 # Web Viewer access
        volumes:
          - ./vm/win11iso/custom.iso:/custom.iso
          - ./vm/win11setup/firstboot:/oem
          - ./vm/win11setup/setupscripts:/data
          - ./vm/win11storage:/storage