Download appi.py from Pezh/Login: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Pezh/Login/resolve/main/appi.py
- Command line
-
hf download hf://spaces/Pezh/Login/appi.py
-
curl -L -o appi.py https://huggingface.co/spaces/Pezh/Login/resolve/main/appi.py
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.") |