Build Image Viewing Streamlit App for Snowflake Users
ฝัง
- เผยแพร่เมื่อ 8 ก.พ. 2025
- In this video we are going to explore, how to build a simple Image Viewing App with Pillow & Streamlit in Snowflake
Prerequisite:
=================
Dealing with Snowflake Unstructured Data Made Easy | In-Depth Intuition
• Dealing with Snowflake...
Reference Links:
==================
docs.snowflake...
github.com/Sno...
Snowflake Code:
==================
drop database if exists s3_to_snowflake;
create database s3_to_snowflake;
--create the external stage with directory table enabled
create or replace stage s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt url="s3://demoexternaltesting/image_storage/"
credentials=(aws_key_id=''
aws_secret_key='')
Directory=(ENABLE=TRUE AUTO_REFRESH=TRUE);
desc stage s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt;
list @s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt;
select * from directory(@s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt);
SELECT RELATIVE_PATH FROM directory(@s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt);
Streamlit Code:
==================
Import python packages
import streamlit as st
from snowflake.snowpark.context import get_active_session
from snowflake.snowpark.files import SnowflakeFile
from PIL import Image
Write directly to the app
st.title("Example Streamlit App :balloon:")
st.write(
"""s3 Image Viewer App"""
)
Get the current credentials
session = get_active_session()
Create an example dataframe
Note: this is just some dummy data, but you can easily connect to your Snowflake data
It is also possible to query data using raw SQL using session.sql() e.g. session.sql("select * from table")
created_dataframe = session.sql("SELECT RELATIVE_PATH FROM directory(@s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt)")
st.write("Extracted Data : ",created_dataframe)
Execute the query and convert it into a Pandas dataframe
queried_data = created_dataframe.to_pandas().values.tolist()
st.write("Pandas Data : ",queried_data)
for i in range(0,len(queried_data)):
queried_data[i]=queried_data[i][0]
st.write("Processed Pandas Data : ",queried_data)
queried_data.insert(0,'Select an Image to preview')
Create a selectbox
selected_option = st.selectbox("Choose an option:", queried_data, placeholder='Select an Image to preview')
if selected_option!='Select an Image to preview':
st.write(f"Selected Image to be displayed: {selected_option}")
ip_file=f"@s3_to_snowflake.PUBLIC.Snow_stage_directory_table_yt/{selected_option}"
bytes_object = session.file.get_stream(ip_file)
image=Image.open(bytes_object)
st.image(image)
Check this playlist for more Data Engineering related videos:
• Demystifying Data Engi...
Apache Kafka form scratch
• Apache Kafka for Pytho...
Messaging Made Easy: AWS SQS Playlist
• Messaging Made Easy: A...
Snowflake Complete Course from scratch with End-to-End Project with in-depth explanation--
doc.clickup.co...
Explore our vlog channel:
/ @funwithourfam