Skip to main content

Toolset for Vision Agent

Project description

vision_agent

🔍🤖 Vision Agent

ci_status PyPI version version

Vision Agent is a library that helps you utilize agent frameworks to generate code to solve your vision task. Many current vision problems can easily take hours or days to solve, you need to find the right model, figure out how to use it and program it to accomplish the task you want. Vision Agent aims to provide an in-seconds experience by allowing users to describe their problem in text and have the agent framework generate code to solve the task for them. Check out our discord for updates and roadmaps!

Documentation

Getting Started

Installation

To get started, you can install the library using pip:

pip install vision-agent

Ensure you have an OpenAI API key and set it as an environment variable (if you are using Azure OpenAI please see the Azure setup section):

export OPENAI_API_KEY="your-api-key"

Vision Agent

You can interact with the agent as you would with any LLM or LMM model:

>>> from vision_agent.agent import VisionAgent
>>> agent = VisionAgent()
>>> code = agent("What percentage of the area of the jar is filled with coffee beans?", media="jar.jpg")

Which produces the following code:

from vision_agent.tools import load_image, grounding_sam

def calculate_filled_percentage(image_path: str) -> float:
    # Step 1: Load the image
    image = load_image(image_path)
    
    # Step 2: Segment the jar
    jar_segments = grounding_sam(prompt="jar", image=image)
    
    # Step 3: Segment the coffee beans
    coffee_beans_segments = grounding_sam(prompt="coffee beans", image=image)
    
    # Step 4: Calculate the area of the segmented jar
    jar_area = 0
    for segment in jar_segments:
        jar_area += segment['mask'].sum()
    
    # Step 5: Calculate the area of the segmented coffee beans
    coffee_beans_area = 0
    for segment in coffee_beans_segments:
        coffee_beans_area += segment['mask'].sum()
    
    # Step 6: Compute the percentage of the jar area that is filled with coffee beans
    if jar_area == 0:
        return 0.0  # To avoid division by zero
    filled_percentage = (coffee_beans_area / jar_area) * 100
    
    # Step 7: Return the computed percentage
    return filled_percentage

To better understand how the model came up with it's answer, you can run it in debug mode by passing in the verbose argument:

>>> agent = VisionAgent(verbose=2)

You can also have it return more information by calling chat_with_workflow:

>>> results = agent.chat_with_workflow([{"role": "user", "content": "What percentage of the area of the jar is filled with coffee beans?"}], media="jar.jpg")
>>> print(results)
{
    "code": "from vision_agent.tools import ..."
    "test": "calculate_filled_percentage('jar.jpg')",
    "test_result": "...",
    "plan": [{"code": "...", "test": "...", "plan": "..."}, ...],
    "working_memory": ...,
}

With this you can examine more detailed information such as the etesting code, testing results, plan or working memory it used to complete the task.

Tools

There are a variety of tools for the model or the user to use. Some are executed locally while others are hosted for you. You can also ask an LLM directly to build a tool for you. For example:

>>> import vision_agent as va
>>> llm = va.llm.OpenAILLM()
>>> detector = llm.generate_detector("Can you build a jar detector for me?")
>>> detector("jar.jpg")
[{"labels": ["jar",],
  "scores": [0.99],
  "bboxes": [
    [0.58, 0.2, 0.72, 0.45],
  ]
}]

Azure Setup

If you want to use Azure OpenAI models, you can set the environment variable:

export AZURE_OPENAI_API_KEY="your-api-key"
export AZURE_OPENAI_ENDPOINT="your-endpoint"

You can then run Vision Agent using the Azure OpenAI models:

>>> import vision_agent as va
>>> agent = va.agent.VisionAgent(
>>>     task_model=va.llm.AzureOpenAILLM(),
>>>     answer_model=va.lmm.AzureOpenAILMM(),
>>>     reflection_model=va.lmm.AzureOpenAILMM(),
>>> )

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

vision_agent-0.2.32.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

vision_agent-0.2.32-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file vision_agent-0.2.32.tar.gz.

File metadata

  • Download URL: vision_agent-0.2.32.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.5.0-1021-azure

File hashes

Hashes for vision_agent-0.2.32.tar.gz
Algorithm Hash digest
SHA256 7f277c57e6829c77aec0a6890dd152b4038249e9acdb3c7200e2b828269aee7a
MD5 548b6838a2362b5753c509441175acab
BLAKE2b-256 cffdcd5bfa77d3bd3fa2e838211c192ea2e0634d3e5a63685c6b8b913a732992

See more details on using hashes here.

File details

Details for the file vision_agent-0.2.32-py3-none-any.whl.

File metadata

  • Download URL: vision_agent-0.2.32-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.5.0-1021-azure

File hashes

Hashes for vision_agent-0.2.32-py3-none-any.whl
Algorithm Hash digest
SHA256 babb2644b3c0e8b8bd09a7025bb6ccf769cc7987085adda244d6f26d1fffb670
MD5 d5a98dfecd85a203d3591f2e728f7677
BLAKE2b-256 de0b12e4cddac23cbf425b801287700060c0882e0adab57afc1ca435583e7f30

See more details on using hashes here.

Supported by

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