Spaces:
Sleeping
Sleeping
trying again for user id
Browse files- app.py +18 -16
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,32 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
import uuid
|
3 |
-
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
)
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
st.stop()
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Generate a new UUID
|
17 |
user_id = str(uuid.uuid4())
|
18 |
-
#
|
19 |
-
|
20 |
-
cookies.save() # Save the cookies
|
21 |
-
else:
|
22 |
-
# Retrieve the user_id from cookies
|
23 |
-
user_id = cookies['user_id']
|
24 |
return user_id
|
25 |
|
26 |
def main():
|
27 |
st.title("Unique User ID with Persistent UUID")
|
28 |
|
29 |
user_id = get_user_id()
|
|
|
30 |
st.write(f"Your user ID is: `{user_id}`")
|
31 |
|
32 |
if __name__ == '__main__':
|
|
|
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__':
|
requirements.txt
CHANGED
@@ -2,4 +2,4 @@ paho-mqtt==2.1.0
|
|
2 |
pillow==10.4.0
|
3 |
setuptools==75.1.0
|
4 |
wheel==0.44.0
|
5 |
-
streamlit-
|
|
|
2 |
pillow==10.4.0
|
3 |
setuptools==75.1.0
|
4 |
wheel==0.44.0
|
5 |
+
extra-streamlit-components==0.1.71
|