Download p.py from Pezh/Login: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/Pezh/Login/resolve/main/p.py
- Command line
-
hf download hf://spaces/Pezh/Login/p.py
-
curl -L -o p.py https://huggingface.co/spaces/Pezh/Login/resolve/main/p.py
1.35 kB
| import streamlit as st | |
| import datetime | |
| import base64 | |
| from datetime import datetime, timedelta | |
| # Function to get the number of remaining clicks for the user | |
| def get_remaining_clicks(): | |
| expiry_time = datetime.utcnow() + timedelta(hours=24) # Set the expiry time for 24 hours from now | |
| user_id = st.report_thread.get_report_ctx().session_id # Get the user's session ID from the report context | |
| click_count = st.session_state.get(user_id, {}).get('click_count', 10) # Get the current click count for the user | |
| expiry_str = expiry_time.strftime('%Y-%m-%d %H:%M:%S') # Convert the expiry time to a string | |
| return click_count, expiry_str | |
| # Function to update the click count for the user | |
| def update_click_count(): | |
| user_id = st.report_thread.get_report_ctx().session_id | |
| click_count, expiry_str = get_remaining_clicks() | |
| click_count -= 1 | |
| st.session_state[user_id] = {'click_count': click_count, 'expiry': expiry_str} | |
| # Main app | |
| def main(): | |
| st.title("Click Counter App") | |
| click_count, expiry_str = get_remaining_clicks() | |
| if click_count > 0: | |
| if st.button("Click"): | |
| update_click_count() | |
| st.write(f"Clicked! You have {click_count-1} clicks remaining.") | |
| else: | |
| st.write("You have used up all your clicks for the next 24 hours.") | |
| if __name__ == "__main__": | |
| main() |