Skip to main content

Give any LLM computer control (VLA) in three lines — Set-of-Mark screen tagging, Pydantic actions, zero-latency OS control.

Project description

Screen2Prompt 🎯

Grant any LLM computer control (VLA) capabilities with just 1 CLI command or 3 lines of code.

PyPI version Python 3.9+ License: MIT

Demo

Screen2Prompt is an open-source VLA (Vision-Language-Action) toolkit[cite: 1]. It captures the screen, applies a Set-of-Mark (numerical tags) to UI elements, and executes OS actions autonomously based on the Pydantic structured output returned by any LLM (OpenAI, Ollama, LM Studio, etc.)[cite: 1].


✨ Key Features

🏷️ Ultimate Set-of-Mark (OpenCV + EasyOCR)

Extracts UI blocks assigning a unique numerical ID to each element[cite: 1].

  • OCR Immunity: Text detected by EasyOCR is guaranteed to be tagged, preventing critical web elements (like search bars) from being filtered out.
  • DPI Aware: Automatically calibrates coordinates for multi-monitor setups and OS display scaling (e.g., 4K monitors).

⚡ Universal LLM Support (Plug-and-Play)

Not locked into OpenAI! Use Ollama, vLLM, or LM Studio seamlessly. Simply override the base_url to run your local AI agent entirely for free.

🔄 Autonomous Closed-Loop & Token Optimization

  • ReAct Feedback Loop: agent.act() automatically captures the new screen state and returns it to the LLM, creating a true autonomous agent.
  • Sliding Window: Prevents API cost explosions and context limit errors by keeping only the most recent visual context and converting older screens to text stubs.

🛡️ Human-in-the-Loop & Advanced OS Control

  • Safety First: CLI prompts a [Y/N] confirmation before executing physical clicks or typing.
  • Rich Action Schema: Supports click, drag, type, wait, press_key (e.g., Enter, Esc), and hotkey (e.g., Win+D). LLMs can actively navigate, wait for loading screens, or recover from errors.

🚀 Hardware Acceleration (GPU / MPS)

By default, Screen2Prompt checks your system environment. If an NVIDIA GPU (CUDA) or Apple Silicon (MPS) is available, it automatically boosts OCR processing speed.

You can also explicitly control hardware acceleration via CLI or Python code:

# Force enable GPU/MPS via CLI
screen2prompt run "Open browser" --gpu
# Enable GPU acceleration in Python
agent = ScreenAgent(gpu=True)

🚀 Quick Start

Installation

pip install screen2prompt
# Note: For NVIDIA GPU acceleration, ensure CUDA is installed for EasyOCR.

1. One-Click CLI Agent (The Magic "Click")

You don't need to write Python code. Control your PC straight from the terminal.

# Using OpenAI (requires OPENAI_API_KEY in .env)
screen2prompt run "Empty the recycle bin"

# Using Local LLM (Ollama) - 100% Free & Private
screen2prompt run "Search the weather on Google" --model ollama/llama3-vision --base-url http://localhost:11434/v1

2. Python API (Custom Integration)

from screen2prompt import ScreenAgent, ActionSchema

agent = ScreenAgent()

# 1. Observe the screen
prompt_data, image_path = agent.observe() 

# 2. Execute Action & Get Feedback (Closed-Loop)
success, new_prompt, new_image = agent.act(
    ActionSchema(action_type="double_click", target_id=12)
)

📦 API Overview

ActionSchema (Pydantic)

Forces all actions into a strict schema, fully compatible with GPT-4o's Structured Outputs[cite: 1].

ActionSchema(
    action_type="click",       # click | double_click | drag | scroll | type | wait | press_key | hotkey | done
    target_id=3,               # ID from the mapping JSON
    destination_id=None,       # Used for drag
    text=None,                 # Used for type
    scroll_clicks=None,        # Used for scroll (positive=up, negative=down)
    wait_seconds=2.5,          # Used for wait (let the LLM decide loading times)
    key_name="enter",          # Used for press_key
    hotkey_names=["win", "d"]  # Used for hotkey combinations
)

🌍 REST API Server

Turn your machine into an accessible AI node.

# Start REST API server (default port 8000)
screen2prompt serve --port 8080 --host 0.0.0.0

Execute Agent via POST:

curl -X POST [http://127.0.0.1:8080/run_agent](http://127.0.0.1:8080/run_agent) \
  -H "Content-Type: application/json" \
  -d '{
        "goal": "Open YouTube and play jazz music",
        "model": "gpt-4o"
      }'

⚙️ Platform Permissions

OS Required Permissions
macOS System Settings → Privacy & Security → Accessibility (Allow Terminal/Python/IDE)[cite: 1]
Windows Allow mouse/keyboard control (Run as Administrator if needed)[cite: 1]

📁 Project Structure

screen2prompt/
├── screen2prompt/
│   ├── __init__.py
│   ├── llm_client.py  # Universal LLM Client (OpenAI API spec)
│   ├── vision.py      # Set-of-Mark & EasyOCR analysis
│   ├── actions.py     # OS control (PyAutoGUI)
│   ├── agent.py       # ScreenAgent + ActionSchema (Closed-Loop)
│   ├── server.py      # FastAPI REST Server
│   └── cli.py         # Terminal CLI
├── setup.py
├── requirements.txt
└── README.md

📄 License

MIT License — Free to use, modify, and distribute[cite: 1].


⭐ Star this repo if Screen2Prompt saves your tokens and your sanity!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

screen2prompt-0.0.2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

screen2prompt-0.0.2-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file screen2prompt-0.0.2.tar.gz.

File metadata

  • Download URL: screen2prompt-0.0.2.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for screen2prompt-0.0.2.tar.gz
Algorithm Hash digest
SHA256 092e26b0d27aac3f94e3a067f4cfe9dc0cc3d3fe01aee0b1b475b1299c38de9c
MD5 682323b1097f8ed9a31b418287fbc739
BLAKE2b-256 935cdb1adc6706cb52cceebf93ff281797975e763d5a88d089164d95001e781b

See more details on using hashes here.

File details

Details for the file screen2prompt-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: screen2prompt-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for screen2prompt-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64c1a98fd586e3d76ddc9b78debd3466b65c4e1d66ade8fa632febe0c5d519f5
MD5 9f711a8730b02e055c5ac0a581d73cb5
BLAKE2b-256 0279f53afabe7b94816bfdb147b6bbb60e34cc0354abdd82c5be017bb6abca51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page