Getting NameError: name ‘get_active_session’ is not defined error while running my code on streamlit:
import streamlit as st
from snowflake.snowpark.context import get_active_session
#import get_active_session
from snowflake.snowpark.functions import col
Write directly to the app
st.title(“ Customize Your Smoothie!
”)
st.write(
“”“Choose the fruits you want in your custom Smoothie!
“””)
#import streamlit as st
name_on_order = st.text_input(“Name on Smoothie:”)
st.write(“The name on your Smoothie will be:”, name_on_order)
from snowflake.snowpark.functions import col
#def get_active_session():
session = get_active_session()
my_dataframe = session.table(“SMOOTHIES.PUBLIC.FRUIT_OPTIONS”).select(col(‘FRUIT_NAME’))
st.dataframe(data=my_dataframe, use_container_width=True)
ingredients_list = st.multiselect(‘Choose up to 5 ingredients:’
, my_dataframe, max_selections=5
)
if ingredients_list:
ingredients_string = ‘’
for fruit_chosen in ingredients_list:
ingredients_string += fruit_chosen + ' '
#st.write(ingredients_string)
my_insert_stmt = """ insert into smoothies.public.orders(ingredients, name_on_order)
values ('""" + ingredients_string + """','""" + name_on_order + """' )"""
time_to_insert = st.button('Submit Order')
if time_to_insert:
session.sql(my_insert_stmt).collect()
st.success('Your Smoothie is ordered!', icon="✅")
st.write(my_insert_stmt)
st.stop()
##if ingredients_string:
# session.sql(my_insert_stmt).collect()
# st.success('Your Smoothie is ordered!', icon="✅")
cnx = st.connection(“snowflake”)
session = cnx.session()
Please help