我正在考虑使用Snowflake的Streamlit App来制作一些验证报告。但是,我找不到信息是否有一种简单的方法可以将数据从雪花阶段(腌制的数据帧、模型文件等)读取到 Streamlit 应用程序。我尝试加载模型文件并打印摘要:
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')
但它不起作用。在此之前,我创建了舞台并放置了模型文件:
CREATE STAGE stage_demo;
-- Put files into stage
put file://C:/Users/cox_model.pkl @database_name.dbo.stage_demo OVERWRITE = TRUE
应用程序在创建阶段和上传模型文件的同一数据库和架构中运行。
FileOperation.getStream
:
@cachetools.cached(cache={})
def read_file():
with session.file.get_stream("@stage_demo/cox_model.pkl") as file:
m = pd.read_pickle(file)
return m