VisionAgent
  • 08 Nov 2024
  • 2 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

In an example code like below, {{your_param_name}} and {{your_file_type}} are placeholders that you need to fill with your actual values.

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

The {{your_param_name}} placeholder is the function parameter name that holds the image or video data. In the following example snippet, the {{your_param_name}} value is image_path.

def count_soda_cans(image_path):
    # Load the image
    image = load_image(image_path)

    # Detect soda cans
    detections = countgd_counting('soda can', image)
    
     # Implementation...
    
    return result

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

After all placeholders are filled out, your code could look like this:

curl -X 'POST' \
  'https://1234lrzim008gn34krx1abcd-webendpoint.sandbox.landing.ai/inference' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'image_path=@/Users/asia/Downloads/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