-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
112 lines (75 loc) · 3.46 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import streamlit as st
# import streamlit_authenticator as stauth
hashed_passwords = stauth.Hasher(['abc', 'def']).generate()
with open('../config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
# import streamlit
# import pandas
# import requests
# from urllib.error import URLError
# streamlit.title('My Parents New Healthy Diner')
# streamlit.header('Breakfast Menu')
# streamlit.text('🥣 Omega 3 & Blueberry Oatmeal')
# streamlit.text('🥗 Kale, Spinach & Rocket Smoothie')
# streamlit.text('🐔 Hard-Boiled Free-Range Egg')
# streamlit.text('🥑🍞 Avocado Toast')
# streamlit.header('🍌🥭 Build Your Own Fruit Smoothie 🥝🍇')
# my_fruit_list = pandas.read_csv("https://uni-lab-files.s3.us-west-2.amazonaws.com/dabw/fruit_macros.txt")
# my_fruit_list = my_fruit_list.set_index('Fruit')
# # Let's put a pick list here so they can pick the fruit they want to include
# fruits_selected = streamlit.multiselect("Pick some fruits:", list(my_fruit_list.index), ['Avocado','Strawberries'])
# fruits_to_show = my_fruit_list.loc[fruits_selected] #pandas.dataFrame.loc[source] Access a group of rows and columns by label(s) or a boolean array.
# # Display the table on the page.
# streamlit.dataframe(fruits_to_show)
# #Create the repeatable code block (called a function)
# def get_fruityvice_data(this_fruit_choice):
# fruityvice_response = requests.get("https://fruityvice.com/api/fruit/" + fruit_choice)
# #take the json version of the response and normalize it
# fruityvice_normalized = pandas.json_normalize(fruityvice_response.json())
# return fruityvice_normalized
# #New Section to display fruityvice api response
# streamlit.header("Fruityvice Fruit Advice!")
# try:
# fruit_choice = streamlit.text_input('What fruit would you like information about?')
# if not fruit_choice:
# streamlit.error("Please select a fruit to get information.")
# else:
# back_from_function=get_fruityvice_data(fruit_choice)
# # output it the screen as table
# streamlit.dataframe(back_from_function)
# except URLError as E:
# streamlit.error()
# streamlit.write('The user entered ', fruit_choice)
# #don't run anything past here while troubleshoot
# # streamlit.stop()
# streamlit.header("View Our Fruit List - Add Your Favorites!")
# #Snowflake-related functions
# def get_fruit_load_list():
# with my_cnx.cursor() as my_cur:
# my_cur.execute("select * from fruit_load_list")
# return my_cur.fetchall()
# #Add a button to load the fruit
# if streamlit.button('Get Fruit List'):
# my_cnx=snowflake.connector.connect(**streamlit.secrets["snowflake"])
# my_data_rows = get_fruit_load_list()
# my_cnx.close()
# streamlit.dataframe(my_data_rows)
# # streamlit.stop() #to troubleshoot
# #Allow the end user to add a fruit to the list
# def insert_row_snowflake(new_fruit):
# with my_cnx.cursor() as my_cur:
# my_cur.execute("insert into fruit_load_list values ('" + new_fruit + "')")
# return "Thanks for adding " + new_fruit
# add_my_fruit = streamlit.text_input('What fruit would you like to add?')
# if streamlit.button('Add a Fruit to the List'):
# my_cnx = snowflake.connector.connect(**streamlit.secrets["snowflake"])
# back_from_function=insert_row_snowflake(add_my_fruit)
# my_cnx.close()
# streamlit.text(back_from_function)