diff --git a/cookies.py b/cookies.py new file mode 100644 index 0000000..57b9997 --- /dev/null +++ b/cookies.py @@ -0,0 +1,48 @@ +import streamlit as st +import time +from cookies_manager import EncryptedCookieManager + +# This should be your unique encryption key, which should be kept secure. +cookie_manager = EncryptedCookieManager( + prefix="myapp_", # Define a prefix for the cookie to avoid conflicts + password="your_secure_cookie_password" # Replace with your secure password +) + +# Initialize cookies +if not cookie_manager.ready(): + st.stop() + + +def get_user_timestamp(): + # Check if timestamp already exists in cookies + timestamp = cookie_manager.get("user_timestamp") + + if timestamp: + st.write(f"Welcome back! Your session started at: {timestamp}") + return timestamp + else: + # Generate a new timestamp in milliseconds + new_timestamp = str(int(time.time() * 1000)) + cookie_manager.set("user_timestamp", new_timestamp, max_age=3600 * 24 * 7) # Store the timestamp for 7 days + st.write(f"New session started! Your timestamp is: {new_timestamp}") + return new_timestamp + + +# Chatbot function +def chatbot(): + st.title("Chatbot with Timestamps in Cookies") + + # Retrieve or create timestamp for the user + timestamp = get_user_timestamp() + + # Display the chat prompt + user_input = st.text_input("You: ", "") + + if user_input: + # Here, instead of querying Ollama, we simulate a chatbot response + st.write(f"**Bot:** You said '{user_input}' at {timestamp}") + + +# Main +if __name__ == "__main__": + chatbot()