Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
@@ -12,17 +12,22 @@ def wakeup_spaces(username: str, hf_token: str="", is_private=True, progress=gr.
|
|
12 |
api = HfApi(token=hf_token if hf_token else HF_TOKEN)
|
13 |
space_infos = api.list_spaces(author=username)
|
14 |
spaces = []
|
|
|
15 |
for s in space_infos:
|
16 |
if s.private and not is_private: continue
|
17 |
spaces.append(s.id)
|
18 |
for s in spaces:
|
19 |
-
|
|
|
20 |
print(f"'{s}' is running.")
|
21 |
progress(0, desc=f"'{s}' is running.")
|
22 |
else:
|
23 |
print(f"'{s}' isn't running. Restarting...")
|
24 |
progress(0, desc=f"'{s}' isn't running. Restarting...")
|
25 |
api.restart_space(repo_id=s)
|
|
|
|
|
|
|
26 |
except Exception as e:
|
27 |
print(f"Error: {e}")
|
28 |
raise gr.Error(f"Error: {e}")
|
|
|
12 |
api = HfApi(token=hf_token if hf_token else HF_TOKEN)
|
13 |
space_infos = api.list_spaces(author=username)
|
14 |
spaces = []
|
15 |
+
logs = []
|
16 |
for s in space_infos:
|
17 |
if s.private and not is_private: continue
|
18 |
spaces.append(s.id)
|
19 |
for s in spaces:
|
20 |
+
stage = api.get_space_runtime(repo_id=s).stage
|
21 |
+
if stage in ("RUNNING", "APP_STARTING", "BUILDING"):
|
22 |
print(f"'{s}' is running.")
|
23 |
progress(0, desc=f"'{s}' is running.")
|
24 |
else:
|
25 |
print(f"'{s}' isn't running. Restarting...")
|
26 |
progress(0, desc=f"'{s}' isn't running. Restarting...")
|
27 |
api.restart_space(repo_id=s)
|
28 |
+
logs.append(f"'{s}' is in '{stage}'.")
|
29 |
+
logs.append(f"'{s}' is restarted.")
|
30 |
+
return "<br>\n".join(logs)
|
31 |
except Exception as e:
|
32 |
print(f"Error: {e}")
|
33 |
raise gr.Error(f"Error: {e}")
|