Spaces:
kakamond
/
Running

admin commited on
Commit
f6ec291
·
1 Parent(s): e8aca46

note useless codes

Browse files
Files changed (1) hide show
  1. app.py +48 -46
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import os
2
  import re
3
- import json
4
  import time
5
- import random
6
- import string
7
  import requests
8
  import schedule
9
  import gradio as gr
@@ -12,6 +9,10 @@ from tqdm import tqdm
12
  from functools import partial
13
  from datetime import datetime, timedelta
14
 
 
 
 
 
15
  TIMEOUT = 15
16
  DELAY = 1
17
 
@@ -46,47 +47,47 @@ def fix_datetime(text: str):
46
  return re.sub(datetime_pattern, add_six_hours, text)
47
 
48
 
49
- def get_studios(username: str):
50
- # 请求负载
51
- payload = {
52
- "PageNumber": 1,
53
- "PageSize": 1000,
54
- "Name": "",
55
- "SortBy": "gmt_modified",
56
- "Order": "desc",
57
- }
58
- try:
59
- # 发送PUT请求
60
- response = requests.put(
61
- f"https://www.modelscope.cn/api/v1/studios/{username}/list",
62
- data=json.dumps(payload),
63
- headers={
64
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
65
- },
66
- timeout=TIMEOUT,
67
- )
68
- # 检查请求是否成功
69
- response.raise_for_status()
70
- # 解析JSON响应
71
- spaces: list = response.json()["Data"]["Studios"]
72
- if spaces:
73
- studios = []
74
- for space in spaces:
75
- studios.append(
76
- f"https://www.modelscope.cn/api/v1/studio/{username}/{space['Name']}/start_expired"
77
- )
78
-
79
- return studios
80
-
81
- except requests.exceptions.Timeout as errt:
82
- print(f"请求超时: {errt}, retrying...")
83
- time.sleep(DELAY)
84
- return get_studios(username)
85
-
86
- except Exception as err:
87
- print(f"请求发生错误: {err}")
88
-
89
- return []
90
 
91
 
92
  def get_spaces(username: str):
@@ -181,9 +182,10 @@ def activate(hf_users: str, ms_users: str):
181
  if not ms_users:
182
  ms_users = hf_users
183
 
184
- spaces, monitors, studios, output = [], [], [], []
 
185
  hf_usernames = hf_users.split(";")
186
- ms_usernames = ms_users.split(";")
187
  for user in tqdm(hf_usernames, desc="Collecting spaces..."):
188
  username = user.strip()
189
  if username:
 
1
  import os
2
  import re
 
3
  import time
 
 
4
  import requests
5
  import schedule
6
  import gradio as gr
 
9
  from functools import partial
10
  from datetime import datetime, timedelta
11
 
12
+ # import json
13
+ # import random
14
+ # import string
15
+
16
  TIMEOUT = 15
17
  DELAY = 1
18
 
 
47
  return re.sub(datetime_pattern, add_six_hours, text)
48
 
49
 
50
+ # def get_studios(username: str):
51
+ # # 请求负载
52
+ # payload = {
53
+ # "PageNumber": 1,
54
+ # "PageSize": 1000,
55
+ # "Name": "",
56
+ # "SortBy": "gmt_modified",
57
+ # "Order": "desc",
58
+ # }
59
+ # try:
60
+ # # 发送PUT请求
61
+ # response = requests.put(
62
+ # f"https://www.modelscope.cn/api/v1/studios/{username}/list",
63
+ # data=json.dumps(payload),
64
+ # headers={
65
+ # "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
66
+ # },
67
+ # timeout=TIMEOUT,
68
+ # )
69
+ # # 检查请求是否成功
70
+ # response.raise_for_status()
71
+ # # 解析JSON响应
72
+ # spaces: list = response.json()["Data"]["Studios"]
73
+ # if spaces:
74
+ # studios = []
75
+ # for space in spaces:
76
+ # studios.append(
77
+ # f"https://www.modelscope.cn/api/v1/studio/{username}/{space['Name']}/start_expired"
78
+ # )
79
+
80
+ # return studios
81
+
82
+ # except requests.exceptions.Timeout as errt:
83
+ # print(f"请求超时: {errt}, retrying...")
84
+ # time.sleep(DELAY)
85
+ # return get_studios(username)
86
+
87
+ # except Exception as err:
88
+ # print(f"请求发生错误: {err}")
89
+
90
+ # return []
91
 
92
 
93
  def get_spaces(username: str):
 
182
  if not ms_users:
183
  ms_users = hf_users
184
 
185
+ # spaces, monitors, studios, output = [], [], [], []
186
+ spaces, output = [], []
187
  hf_usernames = hf_users.split(";")
188
+ # ms_usernames = ms_users.split(";")
189
  for user in tqdm(hf_usernames, desc="Collecting spaces..."):
190
  username = user.strip()
191
  if username: