-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
59 lines (41 loc) · 1.88 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Import python packages
import streamlit as st
import requests, pandas as pd
from snowflake.snowpark.functions import col
# Write directly to the app
st.title(":cup_with_straw: Customize Your Smoothie! :cup_with_straw:")
st.write("Choose the fruits you want in your custom Smoothie!")
name_on_order = st.text_input('Name on Smoothie:')
st.write('The name on your Smoothie will bea:', name_on_order )
cnx = st.connection("snowflake")
session = cnx.session()
my_dataframe = session.table("smoothies.public.fruit_options").select(col('FRUIT_NAME'), col('SEARCH_ON'))
#st.dataframe(data=my_dataframe, use_container_width=True)
#st.stop()
#Convert the Snowpark Dataframe to a Pandas Dataframe so we can use the LOC function
pd_df=my_dataframe.to_pandas()
#st.dataframe(pd_df)
#st.stop()
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 + ' '
search_on=pd_df.loc[pd_df['FRUIT_NAME'] == fruit_chosen, 'SEARCH_ON'].iloc[0]
# st.write('The search value for ', fruit_chosen,' is ', search_on, '.')
st.subheader(fruit_chosen + ' Nutrition Information')
fruityvice_response = requests.get("https://fruityvice.com/api/fruit/" + search_on)
fv_df = st.dataframe(data=fruityvice_response.json(), use_container_width=True)
#st.write(ingredients_string)
my_insert_stmt = """ insert into smoothies.public.orders(ingredients, name_on_order)
values ('""" + ingredients_string + """','""" + name_on_order+ """')"""
#st.write(my_insert_stmt)
#st.stop()
time_to_insert = st.button('Submit Order')
if time_to_insert:
session.sql(my_insert_stmt).collect()
st.success('Your Smoothie is ordered, ' + name_on_order + '!', icon="✅")