Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Alina Lozovskaya
commited on
Commit
·
4cba6f0
1
Parent(s):
463fca1
Improve session manager for a local user
Browse files- yourbench_space/app.py +8 -4
yourbench_space/app.py
CHANGED
|
@@ -152,11 +152,13 @@ def run_evaluation_pipeline(oauth_token: gr.OAuthToken | None, org_name, eval_na
|
|
| 152 |
|
| 153 |
def init_session(profile: gr.OAuthProfile | None):
|
| 154 |
"""Update session on load"""
|
| 155 |
-
if
|
| 156 |
username = "local"
|
| 157 |
-
|
| 158 |
username = profile.username
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
local_uuid = USER_ID_SESSION_MAP.get(username, str(uuid.uuid4()))
|
| 161 |
|
| 162 |
if manager := MANAGERS.get(local_uuid):
|
|
@@ -168,7 +170,9 @@ def init_session(profile: gr.OAuthProfile | None):
|
|
| 168 |
MANAGERS.remove(local_uuid)
|
| 169 |
local_uuid = str(uuid.uuid4())
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
MANAGERS.create(local_uuid)
|
| 173 |
logger.info(f"Started session for {local_uuid}")
|
| 174 |
return gr.State(local_uuid, delete_callback=lambda uid: MANAGERS.remove(uid))
|
|
|
|
| 152 |
|
| 153 |
def init_session(profile: gr.OAuthProfile | None):
|
| 154 |
"""Update session on load"""
|
| 155 |
+
if is_running_locally():
|
| 156 |
username = "local"
|
| 157 |
+
elif profile:
|
| 158 |
username = profile.username
|
| 159 |
+
else:
|
| 160 |
+
username = None
|
| 161 |
+
|
| 162 |
local_uuid = USER_ID_SESSION_MAP.get(username, str(uuid.uuid4()))
|
| 163 |
|
| 164 |
if manager := MANAGERS.get(local_uuid):
|
|
|
|
| 170 |
MANAGERS.remove(local_uuid)
|
| 171 |
local_uuid = str(uuid.uuid4())
|
| 172 |
|
| 173 |
+
if username:
|
| 174 |
+
USER_ID_SESSION_MAP[username] = local_uuid
|
| 175 |
+
|
| 176 |
MANAGERS.create(local_uuid)
|
| 177 |
logger.info(f"Started session for {local_uuid}")
|
| 178 |
return gr.State(local_uuid, delete_callback=lambda uid: MANAGERS.remove(uid))
|