- 16 Sep 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
Run Inference with SQL Commands
- Updated on 16 Sep 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
This article applies to these versions of LandingLens:
LandingLens | LandingLens 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;
Arguments
file_path
A VARCHAR string that defines the location of an image or set of images to run inference on. This can be:
- images in Snowflake, including images in tables
- 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.
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.
The image and the prediction also display on the Deploy page in LandingLens (refresh the page in LandingLens to see the results).
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:
- Open Snowsight.
- Go to Data Products > Apps > LandingLens Visual AI Platform.
- Click Launch App.
- Click App_Wizard.
- Click Settings.
- Expand the Run inferences from SQL statement section. The custom inference function for your instance of LandingLens displays.
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;
Example: Run Inference on an Image in Snowflake
Let's say you've installed the Sample Dataset for LandingLens: LifeSciences Pneumonia dataset from LandingAI. You can then run inference on images from that dataset. For example:
SELECT LLENS_SNW_STAGING.core.run_inference('@llens_sample_ds_lifesciences.pneumonia.dataset/data/normal/IM-0001-0001.jpeg', 'e7fa760c-3472-42e0-b11c-ca219355cb19') as inference;
Example: Run Inference on Images in a Snowflake Table
You can run inference on images in a Snowflake table. For example:
SELECT
LLENS_SNW_STAGING.core.run_inference(file_url_column, 'ac104c43-c6eb-4d1a-8a94-cfaf3dae8f70') as inference
FROM table_with_image_files
WHERE
some_condition = true;