Create app.py
Browse files123456789101112131415161718192021222324252627import streamlit as stfrom datetime import datetime, timedelta
# Check if 'count' and 'reset_time' are already in session_state, if not, initializeif 'count' not in st.session_state: st.session_state.count = 0 st.session_state.reset_time = datetime.utcnow() + timedelta(hours=24)
# Function to handle button clickdef handle_click(): # Check if the reset time has passed and reset count if it has if datetime.utcnow() > st.session_state.reset_time: st.session_state.count = 0 st.session_state.reset_time = datetime.utcnow() + timedelta(hours=24) # Increment the count if it is less than 10 if st.session_state.count < 10: st.session_state.count += 1
# Display the button and attach the handle_click functionst.button('Click it', on_click=handle_click)
# Show the current countst.write(f"Button has been clicked {st.session_state.count} times.")
# Check whether to display the button or notif st.session_state.count >= 10: st.write("You have reached the limit of 10 clicks per 24 hours.")app.pyAdded+27