admin commited on
Commit
7b1592f
1 Parent(s): a056865
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import json
2
  import time
3
  import requests
@@ -40,7 +41,7 @@ def get_studios(username: str):
40
  studios = []
41
  for space in spaces:
42
  studios.append(
43
- f"https://www.modelscope.cn/studios/{username}/{space['Name']}"
44
  )
45
 
46
  return studios
@@ -156,6 +157,12 @@ def activate_space(url: str):
156
 
157
 
158
  def activate(hf_users: str, ms_users: str):
 
 
 
 
 
 
159
  hf_usernames = hf_users.split(";")
160
  ms_usernames = ms_users.split(";")
161
  spaces = []
@@ -173,7 +180,7 @@ def activate(hf_users: str, ms_users: str):
173
 
174
  output = []
175
  for space in tqdm(spaces, desc="Activating spaces..."):
176
- output.append({"space": space, "status": activate_space(space)})
177
  time.sleep(DELAY)
178
 
179
  print("Activation complete!")
@@ -184,6 +191,12 @@ def monitor(hf_users: str, ms_users: str, period=3):
184
  if schedule.get_jobs():
185
  return
186
 
 
 
 
 
 
 
187
  print(f"监控开启中...每 {period} 小时触发")
188
  fixed_activate = partial(activate, hf_users=hf_users, ms_users=ms_users)
189
  schedule.every(period).hours.do(fixed_activate)
@@ -195,7 +208,7 @@ def monitor(hf_users: str, ms_users: str, period=3):
195
  def list_tasks():
196
  jobs = schedule.get_jobs()
197
  if jobs:
198
- return f"{jobs}".replace("[", "").replace("]", "")
199
 
200
  return "None"
201
 
@@ -205,8 +218,14 @@ with gr.Blocks() as iface:
205
  title="Start keeping all spaces active periodically",
206
  fn=monitor,
207
  inputs=[
208
- gr.Textbox(label="HuggingFace", value="monet-joe;MuGeminorum;ccmusic-database", placeholder="Usernames joint by ;"),
209
- gr.Textbox(label="ModelScope", value="monetjoe;MuGeminorum;ccmusic", placeholder="Usernames joint by ;"),
 
 
 
 
 
 
210
  ],
211
  outputs=None,
212
  allow_flagging=False,
@@ -222,8 +241,14 @@ with gr.Blocks() as iface:
222
  title="Test activation for all spaces once",
223
  fn=activate,
224
  inputs=[
225
- gr.Textbox(label="HuggingFace", value="monet-joe;MuGeminorum;ccmusic-database", placeholder="Usernames joint by ;"),
226
- gr.Textbox(label="ModelScope", value="monetjoe;MuGeminorum;ccmusic", placeholder="Usernames joint by ;"),
 
 
 
 
 
 
227
  ],
228
  outputs=gr.Dataframe(label="Activated spaces"),
229
  allow_flagging=False,
 
1
+ import os
2
  import json
3
  import time
4
  import requests
 
41
  studios = []
42
  for space in spaces:
43
  studios.append(
44
+ f"https://www.modelscope.cn/api/v1/studio/{username}/{space['Name']}/start_expired"
45
  )
46
 
47
  return studios
 
157
 
158
 
159
  def activate(hf_users: str, ms_users: str):
160
+ if not hf_users:
161
+ hf_users = os.getenv("hf_users")
162
+
163
+ if not ms_users:
164
+ ms_users = os.getenv("ms_users")
165
+
166
  hf_usernames = hf_users.split(";")
167
  ms_usernames = ms_users.split(";")
168
  spaces = []
 
180
 
181
  output = []
182
  for space in tqdm(spaces, desc="Activating spaces..."):
183
+ output.append({"space": space.split("/")[-1], "status": activate_space(space)})
184
  time.sleep(DELAY)
185
 
186
  print("Activation complete!")
 
191
  if schedule.get_jobs():
192
  return
193
 
194
+ if not hf_users:
195
+ hf_users = os.getenv("hf_users")
196
+
197
+ if not ms_users:
198
+ ms_users = os.getenv("ms_users")
199
+
200
  print(f"监控开启中...每 {period} 小时触发")
201
  fixed_activate = partial(activate, hf_users=hf_users, ms_users=ms_users)
202
  schedule.every(period).hours.do(fixed_activate)
 
208
  def list_tasks():
209
  jobs = schedule.get_jobs()
210
  if jobs:
211
+ return f"{jobs[0]}"
212
 
213
  return "None"
214
 
 
218
  title="Start keeping all spaces active periodically",
219
  fn=monitor,
220
  inputs=[
221
+ gr.Textbox(
222
+ label="HuggingFace",
223
+ placeholder="Usernames joint by ;",
224
+ ),
225
+ gr.Textbox(
226
+ label="ModelScope",
227
+ placeholder="Usernames joint by ;",
228
+ ),
229
  ],
230
  outputs=None,
231
  allow_flagging=False,
 
241
  title="Test activation for all spaces once",
242
  fn=activate,
243
  inputs=[
244
+ gr.Textbox(
245
+ label="HuggingFace",
246
+ placeholder="Usernames joint by ;",
247
+ ),
248
+ gr.Textbox(
249
+ label="ModelScope",
250
+ placeholder="Usernames joint by ;",
251
+ ),
252
  ],
253
  outputs=gr.Dataframe(label="Activated spaces"),
254
  allow_flagging=False,