Run Inference with SQL Commands
  • 30 Aug 2024
  • 1 Minute to read
  • Dark
    Light
  • PDF

Run Inference with SQL Commands

  • Dark
    Light
  • PDF

Article summary

This article applies to these versions of LandingLens:

LandingLensLandingLens on Snowflake

After deploying a model with Cloud Deployment, you can run inference using this function, where APP_NAME is the name of your LandingLens instance:

APP_NAME.core.run_inference(file_path varchar, endpoint_id varchar)

Here is how you select the function:

SELECT APP_NAME.core.run_inference(file_path varchar, endpoint_id varchar) as inference;
Note:
You must be granted the APP_NAME.LLENS_PUBLIC application role to run this function.

Arguments

file_path

A VARCHAR string that defines the location of an image to run inference on. Supported locations are publicly-available HTTP/HTTPS URLs, including publicly-available Amazon S3 URLs.

endpoint_id

A VARCHAR string that defines the endpoint of a model deployed with Cloud Deployment. The endpoint_id displays on the Deploy page in LandingLens.

Endpoint ID

Inference Function Results

Running inference with the function returns prediction results in a JSON format. This is the same format that is returned when running Cloud Deployment using any other method.

Inference Results in Snowsight

The image and the prediction also display on the Deploy page in LandingLens (refresh the page in LandingLens to see the results).

Inference Results in LandingLens

Locate the Function

In APP_NAME.core.run_inference, APP_NAME is the name of your LandingLens application. The name might vary between different LandingLens instances. Get the function for your instance of LandingLens in Snowsight:

  1. Open Snowsight.
  2. Go to Data Products > Apps > LandingLens Visual AI Platform.
  3. Click Launch App.
    Launch App
  4. Click App_Wizard.
  5. Click Settings.
  6. Expand the Run inferences from SQL statement section. The custom inference function for your instance of LandingLens displays.
    Inference Function Information

Grant Application Role

To run inference with a SQL command, you must be granted the APP_NAME.LLENS_PUBLIC application role, where APP_NAME is the name of your LandingLens instance. 

Application roles can't be granted directly to users, so you must grant it to an account role (or to another application role that is then granted to an account role).

For example, the following commands create an account role, grant that role to a user, and then grants the application role to the account role.

CREATE ROLE LANDINGLENS_EXTERNAL_ACCESS;
GRANT ROLE LANDINGLENS_EXTERNAL_ACCESS TO USER <your user>;
GRANT APPLICATION ROLE LLENS_SNW_STAGING.LLENS_PUBLIC TO ROLE LANDINGLENS_EXTERNAL_ACCESS;

Example: Run Inference on an Image Online

The function can run inference on publicly-available HTTP/HTTPS URLs. For example:

SELECT LLENS_SNW_STAGING.core.run_inference('https://upload.wikimedia.org/wikipedia/commons/a/a1/Normal_posteroanterior_%28PA%29_chest_radiograph_%28X-ray%29.jpg', '2c77a3b4-e242-4509-985b-a6fea48a7c47') as inference;

Was this article helpful?

What's Next