admin commited on
Commit
36c5c5a
1 Parent(s): 6c61bf1

refine space print

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -121,7 +121,7 @@ def get_spaces(username: str):
121
 
122
 
123
  def activate_space(url: str):
124
- success = "success"
125
  try:
126
  # 发送GET请求获取页面内容
127
  response = (
@@ -134,18 +134,20 @@ def activate_space(url: str):
134
  if "-keep-spaces-active.hf.space" in url:
135
  start_monitor(url)
136
 
137
- except requests.exceptions.Timeout as errt:
138
- print(f"请求超时: {errt}, retrying...")
139
- time.sleep(DELAY)
140
- return activate_space(url)
 
 
141
 
142
  except requests.RequestException as e:
143
- success = "success" if "500 Server Error:" in f"{e}" else f"{e}"
144
 
145
  except Exception as e:
146
- success = f"{e}"
147
 
148
- return success
149
 
150
 
151
  def activate(hf_users: str, ms_users: str):
@@ -172,7 +174,14 @@ def activate(hf_users: str, ms_users: str):
172
 
173
  output = []
174
  for space in tqdm(spaces, desc="Activating spaces..."):
175
- output.append({"space": space, "status": activate_space(space)})
 
 
 
 
 
 
 
176
  time.sleep(DELAY)
177
 
178
  print("Activation complete!")
@@ -197,7 +206,7 @@ def monitor(hf_users: str, ms_users: str, period=3):
197
  time.sleep(DELAY)
198
 
199
 
200
- def list_tasks():
201
  jobs = schedule.get_jobs()
202
  if jobs:
203
  details = f"{jobs}".replace("[", "").replace("]", "")
@@ -227,7 +236,7 @@ with gr.Blocks() as demo:
227
  )
228
  gr.Interface(
229
  title="See current task status",
230
- fn=list_tasks,
231
  inputs=None,
232
  outputs=gr.Textbox(label="Current task details"),
233
  allow_flagging="never",
 
121
 
122
 
123
  def activate_space(url: str):
124
+ status = "running"
125
  try:
126
  # 发送GET请求获取页面内容
127
  response = (
 
134
  if "-keep-spaces-active.hf.space" in url:
135
  start_monitor(url)
136
 
137
+ except requests.exceptions.Timeout as e:
138
+ if ".hf.space" in url:
139
+ status = "restarting"
140
+ else:
141
+ print(f"Failed to activate {url} : {e}, retrying...")
142
+ return activate_space(url)
143
 
144
  except requests.RequestException as e:
145
+ status = status if "500 Server Error:" in f"{e}" else f"{e}"
146
 
147
  except Exception as e:
148
+ status = f"{e}"
149
 
150
+ return status
151
 
152
 
153
  def activate(hf_users: str, ms_users: str):
 
174
 
175
  output = []
176
  for space in tqdm(spaces, desc="Activating spaces..."):
177
+ output.append(
178
+ {
179
+ "space": space.split("//")[-1].replace(
180
+ "www.modelscope.cn/api/v1/studio/", ""
181
+ ),
182
+ "status": activate_space(space),
183
+ }
184
+ )
185
  time.sleep(DELAY)
186
 
187
  print("Activation complete!")
 
206
  time.sleep(DELAY)
207
 
208
 
209
+ def listasks():
210
  jobs = schedule.get_jobs()
211
  if jobs:
212
  details = f"{jobs}".replace("[", "").replace("]", "")
 
236
  )
237
  gr.Interface(
238
  title="See current task status",
239
+ fn=listasks,
240
  inputs=None,
241
  outputs=gr.Textbox(label="Current task details"),
242
  allow_flagging="never",