I am considering to use Snowflake’s Streamlit App to make some validation reports. However, I cannot find information is there an easy way to read data from snowflake stage (pickled data frames, model files, etc.) to Streamlit application. I tried to load model file and print summary like that:
import streamlit as st
from snowflake.snowpark.context import get_active_session
import pandas as pd
import sys
import os
import cachetools
# Get the current credentials
session = get_active_session()
session.add_import("@stage_demo/cox_model.pkl")
@cachetools.cached(cache={})
def read_file(filename):
import_dir = sys._xoptions.get("snowflake_import_directory")
if import_dir:
with open(os.path.join(import_dir, filename), 'rb') as file:
m = pd.read_pickle(file)
return m
cph = read_file('cox_model.pkl')
and it did not work. Before that, I created stage and put model file:
CREATE STAGE stage_demo;
-- Put files into stage
put file://C:/Users/cox_model.pkl @database_name.dbo.stage_demo OVERWRITE = TRUE
Application runs in the same database and schema where stage is created and model file is uploaded.