VisionAgent
  • 13 Dec 2024
  • 3 Minutes to read
  • Dark
    Light
  • PDF

VisionAgent

  • Dark
    Light
  • PDF

Article summary

Deploy VisionAgent-Generated Code

You can test code generated by VisionAgent by deploying it directly from the app. We’ve developed a few different deployment methods to offer flexibility for a variety of workflows. 

To start the deployment process, click Deploy.

Deploy the Generate Code

You can then choose your deployment options:

Choose a Deployment Option

Hosted Deployment: Python and Shell

VisionAgent offers a Hosted on Web API option. With this method, VisionAgent hosts the code file, and generates Python and Shell scripts that you can run.

Copy one of the scripts, paste it into your runtime environment, and fill out the placeholders with your information (like the file path to images you want to run through the code). When you run the script, the selected files are sent to the hosted code, and the results display in your runtime environment.

Data Formats for Shell Code

When you select the Shell code, you can select the data format for the images or videos that you will send to the VisionAgent-hosted code. These data formats are available:

  • HTTP URL: Add the URL to a remote image for video.
  • File: Add the file path to the image or video. If you choose this option, the content-type of your HTTP request must be “multipart/form-data”. The generated script will include an example that shows how to use this.

Data Formats for Python Code

When you select the Python code, you can select the data format for the images or videos that you will send to the VisionAgent-hosted code. These data formats are available:

  • HTTP URL: Add the URL to a remote image for video.
  • base64-encoded string: This encodes the image or video binary data

Supported Content-Types

For the HTTP URL and base64 data formats, the web endpoint supports the following content-types:

  • application/json
  • application/x-www-form-urlencoded
  • multipart/form-data

Base64: Data URL String Format

For the base64 data format, you must follow the Data URL string format

For images, this is: “data:image/{YOUR_IMAGE_TYPE};base64,{YOUR_BASE64_STRING}”

For videos, this is: “data:video/{YOUR_VIDEO_TYPE};base64,{YOUR_BASE64_STRING}”

For example, options could be “data:image/jpeg;base64,......” or “data:video/mp4;base64,.....”.

Fill Out Placeholders

The deployment code includes the following placeholders that you need to fill in with your actual values:

For example, here is a sample shell deployment script with the placeholders. The following sections show how these placeholders can be filled out.

curl -X 'POST' \
  'https://1234-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Authorization: Basic {{your_api_key}}' \
  -F '{{your_param_name}}=@{{your_file_path}};type={{your_file_type}}'

{{your_api_key}}

Replace the {{your_api_key}} placeholder with your VisionAgent API Key. There are two ways to get your API Key:

  • Click the API Key link at the bottom of the Deploy pop-up
  • Click your Profile in the top right corner. Then click your name > API Key.

Here is a sample script with the {{your_api_key}} placeholder filled out:

curl -X 'POST' \
  'https://1234-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Authorization: Basic bDk1234abcdA==' \
  -F '{{your_param_name}}=@{{your_file_path}};type={{your_file_type}}'

{{your_param_name}}

The {{your_param_name}} placeholder is the function parameter that holds the image or video data. The function is defined in the code generated by VisionAgent.

For example, in the VisionAgent-generated code below, the function parameter is image_path.

Locate the Function Parameter for the Function That Contains the File Data

Here is a sample script with the {{your_param_name}} placeholder filled out:

curl -X 'POST' \
  'https://1234-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Authorization: Basic bDk1234abcdA==' \
  -F 'image_path=@{{your_file_path}};type={{your_file_type}}'

{{your_file_path}} or {{image_url}}

Replace the {{your_file_path}} or {{image_url}} placeholder with the location of the file you want to run the code on.

Here is a sample script with the {{your_file_path}}  placeholder filled out:

curl -X 'POST' \
  'https://1234-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Authorization: Basic bDk1234abcdA==' \
  -F 'image_path=@RzyK8k6mw/soda.png;type={{your_file_type}}'

{{your_file_type}}

Replace the {{your_file_type}} placeholder with the file extension of your image or video file type with the prefix image/ or video/. For example, options could be image/png or video/mp4.

Here is a sample script with the {{your_file_type}} placeholder filled out:

curl -X 'POST' \
  'https://1234-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Authorization: Basic bDk1234abcdA==' \
  -F 'image_path=@RzyK8k6mw/soda.png;type=image/png'

Endpoint Lifecycle

Currently, the hosted endpoints are intended for prototyping and testing purposes. When an endpoint is deployed, it will be available for 7 days.

If you want to test VisionAgent code after an endpoint has been de-activated, simply click the Deploy button again. The de-activated endpoint will become active again and any previously generated scripts will work again.

Endpoint Specifications

The hosted endpoints have the following specifications:

  • Supported image types: PNG, JPEG, TIFF, HEIF and other types supported by PIL (for more types, go here; for implementation details, go here).
  • Supported video types: MP4, AVI, WEBM, and other types supported by OpenCV (for implementation details, go here).
  • Maximum video file size: 64MB

Test in the UI via a Streamlit App

VisionAgent has a built-in Streamlit app that lets you test out the generated code. Click Deploy > Streamlit App, and then upload an image. VisionAgent runs the code on the image and shows the results. 

Load an Image via Drag and Drop

Was this article helpful?

What's Next