Alina Lozovskaya commited on
Commit
463fca1
·
1 Parent(s): 50871c5

Additional session fixes

Browse files
Files changed (1) hide show
  1. yourbench_space/app.py +15 -11
yourbench_space/app.py CHANGED
@@ -152,19 +152,23 @@ 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 profile is None: # if we running localy or user is not logged in
156
- local_uuid = "local" if is_running_locally() else str(uuid.uuid4())
157
  else:
158
- local_uuid = USER_ID_SESSION_MAP.get(profile.username, str(uuid.uuid4()))
159
-
160
- manager = MANAGERS.get(local_uuid)
161
- if manager and manager.is_running():
162
- logger.info(f"Found existing, running session for {local_uuid}")
163
- return gr.State(local_uuid, delete_callback=lambda uid: MANAGERS.remove(uid))
164
-
165
- if profile:
166
- USER_ID_SESSION_MAP[profile.username] = local_uuid
167
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  MANAGERS.create(local_uuid)
169
  logger.info(f"Started session for {local_uuid}")
170
  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 profile is None:
156
+ username = "local"
157
  else:
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):
163
+ if manager.is_running():
164
+ logger.info(f"Found existing running session for {local_uuid}, restoring")
165
+ return gr.State(local_uuid, delete_callback=lambda uid: MANAGERS.remove(uid))
166
+ else:
167
+ logger.info(f"Found existing stale session for {local_uuid}, starting new")
168
+ MANAGERS.remove(local_uuid)
169
+ local_uuid = str(uuid.uuid4())
170
+
171
+ USER_ID_SESSION_MAP[username] = local_uuid
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))