File size: 1,350 Bytes
f630872
 
 
 
350c15f
 
 
f630872
 
 
 
 
350c15f
613e418
f630872
 
350c15f
 
613e418
 
350c15f
 
 
613e418
350c15f
f630872
 
350c15f
 
 
 
f630872
 
 
 
 
 
 
350c15f
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
import streamlit as st
from datetime import timedelta

# Function to cache user data
@st.cache(allow_output_mutation=True, ttl=timedelta(days=1), show_spinner=True)
def cache_user_data():
    return {'email': '', 'phone': '', 'password': ''}

# Main app function
def main():
    st.title('User Data Caching Example')

    # Retrieve or initialize cached data
    cached_data = cache_user_data()

    # Input fields with emojis
    new_email = st.text_input("πŸ“§ Email Address", value=cached_data['email'])
    new_phone = st.text_input("πŸ“± Mobile Phone", value=cached_data['phone'])

    # Password field with an option to view contents
    show_password = st.checkbox("Show password")
    if show_password:
        new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'])
    else:
        new_password = st.text_input("πŸ”‘ Password", value=cached_data['password'], type='password')

    # Update cache if data changes
    if new_email != cached_data['email'] or new_phone != cached_data['phone'] or new_password != cached_data['password']:
        cached_data['email'] = new_email
        cached_data['phone'] = new_phone
        cached_data['password'] = new_password
        st.success("Data updated and cached!")

    st.write("Cached Data:")
    st.json(cached_data)

# Run the app
if __name__ == "__main__":
    main()