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