Snowflake has simplified the integration of Machine Learning models into Data Applications through its convenient features that allow for the deployment of ML models as Stored Procedures, User Defined Functions (UDF's), and User Defined Table Functions (UDTF's). Furthermore, Snowflake offers a SQL API, a RESTful API to facilitate querying the deployed ML models, enabling seamless integration between the application and the ML model.
In this tutorial, the application you are building helps fictitious food truck company, Tasty Bytes and it's Truck drivers to view the location recommendations provided by the ML model directly in the Data Application. This Location Recommendation ML model is built within Snowflake using Snowpark which makes it easy for python users to leverage Snowflake platform. This model uses historical sales data and Safegraph weather data from Snowflake Data Marketplace to provide more information to the model. This tutorial will guide you through the process of how we are deploying and integrating ML model into the Truck Driver App.
To run the app locally,
- Clone the repo using
git clone https://github.com/sf-gh-sjasti/IntegrationTastyBytesMLModelInDataApp.git reactNativeMLApp
- Navigate to the folder,
cd reactNativeMLApp
- Run
npm install
to install dependancies
- Open the
reactNativeMLApp
folder in VS Code or IDE of your choice. - Open the
.env
file and updatePRIVATE_KEY
value with the private key. Copy and paste the whole private key from~/.ssh/snowflake_app_key.pub
including header(-----BEGIN RSA PRIVATE KEY-----
) and footer(-----END RSA PRIVATE KEY-----
). - If you are located in us-west region, Update
SNOWFLAKE_ACCOUNT_IDENTIFIER
with your Snowflake Account (or) If you are located outside the us-west region, UpdateSNOWFLAKE_ACCOUNT_IDENTIFIER
as '.'. To get the snowflake_account value from Snowflake, runSELECT CURRENT_ACCOUNT()
in Snowsight. To get the region value from Snowflake, runSELECT CURRENT_REGION()
in Snowsight. SNOWFLAKE_ACCOUNT_IDENTIFIER and SNOWFLAKE_ACCOUNT would be same for us-west. - Update
SNOWFLAKE_ACCOUNT
with your Snowflake Account. - Update
PUBLIC_KEY_FINGERPRINT
with your user Public Key FingerPrint. To get Public Key Fingerprint, Run the following SQL in SnowsightDESCRIBE USER data_app_demo
and get RSA_PUBLIC_KEY_FP property value.
We are using Key Pair Authentication to authenticate with Snowflake using SQL API. You can refer to the Tokens.js
to understand how we are generating the JWT token. Locations.js
has the source code to render Locations screen. You can also refer to this file to find out how to query UDF using SQL API and the headers needed.
- Run
npx expo start --clear
and hitw
key to run the app in a web browser - This launches the app in Web Browser
- Upon Launch, You can see the List of recommendations with predicted shift sales.
For detailed steps, Refer to the Quickstart, https://quickstarts.snowflake.com/guide/integrating_tasty_bytes_location_recommendation_ml_model_into_the_react_native_data_app