awacke1 commited on
Commit
350c15f
Β·
verified Β·
1 Parent(s): 613e418

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
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.cache_resource(ttl=timedelta(days=1), max_entries=10, show_spinner=True)
6
- def cache_user_data(email="", phone="", password=""):
7
- return {'email': email, 'phone': phone, 'password': password}
8
 
9
  # Main app function
10
  def main():
11
  st.title('User Data Caching Example')
12
 
13
- # Retrieve cached data if it exists
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
- password_placeholder = st.empty()
23
- if st.checkbox("Show password"):
24
- new_password = password_placeholder.text_input("πŸ”‘ Password", value=password)
25
  else:
26
- new_password = password_placeholder.text_input("πŸ”‘ Password", value=password, type='password')
27
 
28
  # Update cache if data changes
29
- if new_email != email or new_phone != phone or new_password != password:
30
- cache_user_data(new_email, new_phone, new_password)
 
 
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()