Spaces:
Sleeping
Sleeping
Create backup.app.py
Browse files- backup.app.py +40 -0
backup.app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
@st.cache(suppress_st_warning=True,allow_output_mutation=True, ttl=86400) # 86400 seconds = 1 day
|
4 |
+
#@st.cache_data(ttl=86400) # 86400 seconds = 1 day
|
5 |
+
#@st.cache(suppress_st_warning=True, ttl=86400)
|
6 |
+
#@st.cache_data(experimental_allow_widgets=True) # π Set the parameter
|
7 |
+
def cache_user_data():
|
8 |
+
return {'email': '', 'phone': '', 'password': ''}
|
9 |
+
|
10 |
+
#@st.cache_data(experimental_allow_widgets=True) # π Set the parameter
|
11 |
+
def main():
|
12 |
+
st.title('User Data Caching Example')
|
13 |
+
|
14 |
+
# Retrieve or initialize cached data
|
15 |
+
cached_data = cache_user_data()
|
16 |
+
|
17 |
+
# Input fields with emojis
|
18 |
+
new_email = st.text_input("π§ Email Address", value=cached_data['email'])
|
19 |
+
new_phone = st.text_input("π± Mobile Phone", value=cached_data['phone'])
|
20 |
+
|
21 |
+
# Password field with an option to view contents
|
22 |
+
show_password = st.checkbox("Show password")
|
23 |
+
if show_password:
|
24 |
+
new_password = st.text_input("π Password", value=cached_data['password'])
|
25 |
+
else:
|
26 |
+
new_password = st.text_input("π Password", value=cached_data['password'], type='password')
|
27 |
+
|
28 |
+
# Update cache if data changes
|
29 |
+
if new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']:
|
30 |
+
cached_data['email'] = new_email
|
31 |
+
cached_data['phone'] = new_phone
|
32 |
+
cached_data['password'] = new_password
|
33 |
+
st.success("Data updated and cached!")
|
34 |
+
|
35 |
+
st.write("Cached Data:")
|
36 |
+
st.json(cached_data)
|
37 |
+
|
38 |
+
# Run the app
|
39 |
+
if __name__ == "__main__":
|
40 |
+
main()
|