Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Clémentine
commited on
Commit
·
8c14d95
1
Parent(s):
8cc9490
last nits with session management
Browse files- yourbench_space/app.py +10 -7
- yourbench_space/utils.py +4 -2
yourbench_space/app.py
CHANGED
@@ -42,9 +42,10 @@ 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 |
-
|
|
|
48 |
for _ in range(5):
|
49 |
time.sleep(0.5)
|
50 |
if config_path.exists():
|
@@ -59,9 +60,11 @@ def generate_and_return(hf_org, hf_dataset_name, uuid: str):
|
|
59 |
|
60 |
final_dataset = None
|
61 |
|
62 |
-
def update_process_status(
|
63 |
"""Update process status and include exit details if process has terminated"""
|
64 |
-
|
|
|
|
|
65 |
|
66 |
is_running = manager.is_running()
|
67 |
|
@@ -72,12 +75,12 @@ def update_process_status(uuid: str):
|
|
72 |
|
73 |
return gr.update(value=True, label="Process Status: Running")
|
74 |
|
75 |
-
def prepare_task(
|
76 |
new_env = os.environ.copy()
|
77 |
if oauth_token:
|
78 |
new_env["HF_TOKEN"] = oauth_token.token
|
79 |
new_env["DATASET_PREFIX"] = hf_dataset_name
|
80 |
-
MANAGERS.start_process(
|
81 |
|
82 |
|
83 |
def update_hf_org_dropdown(oauth_token: gr.OAuthToken | None):
|
|
|
42 |
else "# Citation\n\nDocumentation file not found."
|
43 |
)
|
44 |
|
45 |
+
def generate_and_return(hf_org, hf_dataset_name, session_state: gr.State):
|
46 |
+
manager = MANAGERS.get(session_state)
|
47 |
+
session_uid = session_state.value
|
48 |
+
config_path = generate_and_save_config(hf_org, hf_dataset_name, session_uid, manager.config_path)
|
49 |
for _ in range(5):
|
50 |
time.sleep(0.5)
|
51 |
if config_path.exists():
|
|
|
60 |
|
61 |
final_dataset = None
|
62 |
|
63 |
+
def update_process_status(session_state: gr.State):
|
64 |
"""Update process status and include exit details if process has terminated"""
|
65 |
+
if session_state is None:
|
66 |
+
return gr.update(value=False, label="Not running")
|
67 |
+
manager = MANAGERS.get(session_state.value)
|
68 |
|
69 |
is_running = manager.is_running()
|
70 |
|
|
|
75 |
|
76 |
return gr.update(value=True, label="Process Status: Running")
|
77 |
|
78 |
+
def prepare_task(session_uid: str, oauth_token: gr.OAuthToken | None, hf_dataset_name: str, _=None):
|
79 |
new_env = os.environ.copy()
|
80 |
if oauth_token:
|
81 |
new_env["HF_TOKEN"] = oauth_token.token
|
82 |
new_env["DATASET_PREFIX"] = hf_dataset_name
|
83 |
+
MANAGERS.start_process(session_uid, custom_env=new_env)
|
84 |
|
85 |
|
86 |
def update_hf_org_dropdown(oauth_token: gr.OAuthToken | None):
|
yourbench_space/utils.py
CHANGED
@@ -118,6 +118,8 @@ class SubprocessManagerGroup:
|
|
118 |
self.managers[uid].kill_process()
|
119 |
|
120 |
def read_and_get_output(self, uid: Union[str, gr.State]):
|
|
|
|
|
121 |
uid = SubprocessManagerGroup.grab_uuid(uid)
|
122 |
return self.managers[uid].read_and_get_output()
|
123 |
|
@@ -125,9 +127,9 @@ class SubprocessManagerGroup:
|
|
125 |
class SubprocessManager:
|
126 |
def __init__(self, session_uid: str):
|
127 |
self.session_uid = session_uid
|
128 |
-
self.path = pathlib.Path(f"
|
129 |
self.path.mkdir(parents=True, exist_ok=True)
|
130 |
-
self.config_path = pathlib.Path(f"
|
131 |
self.command = ["uv", "run", "yourbench", f"--config", str(self.config_path)]
|
132 |
self.process = None
|
133 |
self.output_stream = io.StringIO()
|
|
|
118 |
self.managers[uid].kill_process()
|
119 |
|
120 |
def read_and_get_output(self, uid: Union[str, gr.State]):
|
121 |
+
if uid is None:
|
122 |
+
return "", []
|
123 |
uid = SubprocessManagerGroup.grab_uuid(uid)
|
124 |
return self.managers[uid].read_and_get_output()
|
125 |
|
|
|
127 |
class SubprocessManager:
|
128 |
def __init__(self, session_uid: str):
|
129 |
self.session_uid = session_uid
|
130 |
+
self.path = pathlib.Path(f"app/{session_uid}")
|
131 |
self.path.mkdir(parents=True, exist_ok=True)
|
132 |
+
self.config_path = pathlib.Path(f"{self.path}/config.yml")
|
133 |
self.command = ["uv", "run", "yourbench", f"--config", str(self.config_path)]
|
134 |
self.process = None
|
135 |
self.output_stream = io.StringIO()
|