Spaces:
Sleeping

Login / appi.py
Pezh's picture
Rename app.py to appi.py
13380f9 verified
Raw History Blame Contribute Delete
1.05 kB
import streamlit as st
from datetime import datetime, timedelta
# Check if 'count' and 'reset_time' are already in session_state, if not, initialize
if '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 click
def 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 function
st.button('Click it', on_click=handle_click)
# Show the current count
st.write(f"Button has been clicked {st.session_state.count} times.")
# Check whether to display the button or not
if st.session_state.count >= 10:
st.write("You have reached the limit of 10 clicks per 24 hours.")