awacke1's picture
Update app.py
350c15f verified
raw
history blame
1.35 kB
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()