gursi26 commited on
Commit
2e1ca7b
1 Parent(s): a887238

trial with text file

Browse files
Files changed (1) hide show
  1. app.py +12 -30
app.py CHANGED
@@ -1,35 +1,17 @@
1
  import streamlit as st
2
  import uuid
3
- import extra_streamlit_components as stx
4
- from datetime import datetime
5
 
6
- def get_user_id():
7
- # Initialize CookieManager
8
- cookie_manager = stx.CookieManager()
9
 
10
- # Get all cookies
11
- cookies = cookie_manager.get_all()
 
 
 
 
 
 
12
 
13
- if not cookies:
14
- # Cookies are not ready yet
15
- st.write("Loading user ID...")
16
- st.stop()
17
-
18
- user_id = cookies.get('user_id')
19
-
20
- if user_id is None:
21
- # Generate a new UUID
22
- user_id = str(uuid.uuid4())
23
- # Set the cookie (expires in 10 years)
24
- cookie_manager.set('user_id', user_id, expires_at=datetime.fromisoformat("2033-01-01T00:00:00"))
25
- return user_id
26
-
27
- def main():
28
- st.title("Unique User ID with Persistent UUID")
29
-
30
- user_id = get_user_id()
31
-
32
- st.write(f"Your user ID is: `{user_id}`")
33
-
34
- if __name__ == '__main__':
35
- main()
 
1
  import streamlit as st
2
  import uuid
3
+ import os
 
4
 
5
+ # File to store the UUID
6
+ uuid_file = "uuid.txt"
 
7
 
8
+ # Check if the UUID is already saved, otherwise generate and save it
9
+ if os.path.exists(uuid_file):
10
+ with open(uuid_file, "r") as file:
11
+ saved_uuid = file.read().strip()
12
+ else:
13
+ saved_uuid = str(uuid.uuid4())
14
+ with open(uuid_file, "w") as file:
15
+ file.write(saved_uuid)
16
 
17
+ st.text_input("Your Textbox", value=saved_uuid)