Spaces:
Sleeping
Sleeping
Clémentine
commited on
Commit
·
9844319
1
Parent(s):
0532841
fix session state management
Browse files- yourbench_space/app.py +8 -8
- yourbench_space/utils.py +1 -2
yourbench_space/app.py
CHANGED
@@ -42,9 +42,9 @@ citation_content = (
|
|
42 |
else "# Citation\n\nDocumentation file not found."
|
43 |
)
|
44 |
|
45 |
-
def generate_and_return(hf_org, hf_dataset_name,
|
46 |
-
manager = MANAGERS.get(
|
47 |
-
config_path = generate_and_save_config(hf_org, hf_dataset_name,
|
48 |
for _ in range(5):
|
49 |
time.sleep(0.5)
|
50 |
if config_path.exists():
|
@@ -59,9 +59,9 @@ def generate_and_return(hf_org, hf_dataset_name, session_state: gr.State):
|
|
59 |
|
60 |
final_dataset = None
|
61 |
|
62 |
-
def update_process_status(
|
63 |
"""Update process status and include exit details if process has terminated"""
|
64 |
-
manager = MANAGERS.get(
|
65 |
|
66 |
is_running = manager.is_running()
|
67 |
|
@@ -72,8 +72,8 @@ def update_process_status(session_state: gr.State):
|
|
72 |
|
73 |
return gr.update(value=True, label="Process Status: Running")
|
74 |
|
75 |
-
def prepare_task(
|
76 |
-
manager = MANAGERS.get(
|
77 |
new_env = os.environ.copy()
|
78 |
if oauth_token:
|
79 |
new_env["HF_TOKEN"] = oauth_token.token
|
@@ -134,7 +134,7 @@ def run_evaluation_pipeline(oauth_token: gr.OAuthToken | None, org_name, eval_na
|
|
134 |
with gr.Blocks(theme=gr.themes.Default()) as app:
|
135 |
# We initialize the session state with the user randomly generated uuid
|
136 |
# Using uuid4 makes collision cases extremely unlikely even for concurrent users
|
137 |
-
session_state = gr.State(uuid.uuid4(), delete_callback=lambda uid: MANAGERS.remove(uid))
|
138 |
MANAGERS.create(session_state.value)
|
139 |
|
140 |
gr.Markdown(project_description)
|
|
|
42 |
else "# Citation\n\nDocumentation file not found."
|
43 |
)
|
44 |
|
45 |
+
def generate_and_return(hf_org, hf_dataset_name, uuid: str):
|
46 |
+
manager = MANAGERS.get(uuid)
|
47 |
+
config_path = generate_and_save_config(hf_org, hf_dataset_name, uuid, manager.config_path)
|
48 |
for _ in range(5):
|
49 |
time.sleep(0.5)
|
50 |
if config_path.exists():
|
|
|
59 |
|
60 |
final_dataset = None
|
61 |
|
62 |
+
def update_process_status(uuid: str):
|
63 |
"""Update process status and include exit details if process has terminated"""
|
64 |
+
manager = MANAGERS.get(uuid)
|
65 |
|
66 |
is_running = manager.is_running()
|
67 |
|
|
|
72 |
|
73 |
return gr.update(value=True, label="Process Status: Running")
|
74 |
|
75 |
+
def prepare_task(uuid: str, oauth_token: gr.OAuthToken | None, hf_dataset_name: str, _=None):
|
76 |
+
manager = MANAGERS.get(uuid)
|
77 |
new_env = os.environ.copy()
|
78 |
if oauth_token:
|
79 |
new_env["HF_TOKEN"] = oauth_token.token
|
|
|
134 |
with gr.Blocks(theme=gr.themes.Default()) as app:
|
135 |
# We initialize the session state with the user randomly generated uuid
|
136 |
# Using uuid4 makes collision cases extremely unlikely even for concurrent users
|
137 |
+
session_state = gr.State(str(uuid.uuid4()), delete_callback=lambda uid: MANAGERS.remove(uid))
|
138 |
MANAGERS.create(session_state.value)
|
139 |
|
140 |
gr.Markdown(project_description)
|
yourbench_space/utils.py
CHANGED
@@ -24,9 +24,8 @@ STAGES = [
|
|
24 |
]
|
25 |
|
26 |
|
27 |
-
def save_files(
|
28 |
"""Save uploaded files to the UPLOAD_DIRECTORY/uuid safely"""
|
29 |
-
uuid = session_state.value
|
30 |
saved_paths = []
|
31 |
|
32 |
for file in files:
|
|
|
24 |
]
|
25 |
|
26 |
|
27 |
+
def save_files(uuid: str, files: List[pathlib.Path]) -> str:
|
28 |
"""Save uploaded files to the UPLOAD_DIRECTORY/uuid safely"""
|
|
|
29 |
saved_paths = []
|
30 |
|
31 |
for file in files:
|