Update ff.py
Browse files
ff.py
CHANGED
|
@@ -121,8 +121,8 @@ def telegram_message(bot_token: str, chat_id: str, message: str):
|
|
| 121 |
return response.json()
|
| 122 |
except Exception:
|
| 123 |
return {"status_code": response.status_code, "text": response.text}
|
| 124 |
-
|
| 125 |
-
def create_space(type,key = "", value = ""):
|
| 126 |
if type == 1:
|
| 127 |
# 创建spaces
|
| 128 |
url = "https://huggingface.co/api/repos/create"
|
|
@@ -130,9 +130,9 @@ def create_space(type,key = "", value = ""):
|
|
| 130 |
"Content-Type": "application/json",
|
| 131 |
"Authorization": f"Bearer {HF_TOKON2}"
|
| 132 |
}
|
| 133 |
-
|
| 134 |
payload = {
|
| 135 |
-
"name":
|
| 136 |
"type": "space",
|
| 137 |
"private": True,
|
| 138 |
"sleepTimeSeconds": 172800,
|
|
@@ -157,7 +157,7 @@ def create_space(type,key = "", value = ""):
|
|
| 157 |
return response.text
|
| 158 |
if type == 3:
|
| 159 |
# 创建spaces 变量
|
| 160 |
-
url = f"https://huggingface.co/api/spaces/{HF_USER2}/{
|
| 161 |
headers = {
|
| 162 |
"Content-Type": "application/json",
|
| 163 |
"Authorization": f"Bearer {HF_TOKON2}"
|
|
@@ -170,15 +170,15 @@ def create_space(type,key = "", value = ""):
|
|
| 170 |
response = requests.post(url, headers=headers, json=payload)
|
| 171 |
return response.text
|
| 172 |
if type == 4:
|
| 173 |
-
file_path = f"/data/{
|
| 174 |
os.system("rm -rf {HF_SPACES_NAME}")
|
| 175 |
-
git = f"git clone https://{HF_USER2}:{HF_TOKON2}@huggingface.co/spaces/{HF_USER2}/{
|
| 176 |
url = "https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile"
|
| 177 |
print(git)
|
| 178 |
os.system(git)
|
| 179 |
os.system(f'git config --global user.email "{HF_EMAIL2}"')
|
| 180 |
os.system(f'git config --global user.name "{HF_USER2}"')
|
| 181 |
-
os.chdir(f'/data/{
|
| 182 |
time.sleep(3)
|
| 183 |
# 如果文件已存在,先删除
|
| 184 |
if os.path.exists(file_path):
|
|
@@ -197,7 +197,7 @@ def create_space(type,key = "", value = ""):
|
|
| 197 |
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}下载Dockerfile下载失败,状态码: {response.status_code}")
|
| 198 |
|
| 199 |
# os.system(f"wget -O '/data/{tmp_name}/Dockerfile' https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile")
|
| 200 |
-
repo_path = f"/data/{
|
| 201 |
subprocess.run(["git", "-C", repo_path, "add", "."], check=True)
|
| 202 |
subprocess.run(["git", "-C", repo_path, "commit", "-m", commit_message], check=True)
|
| 203 |
subprocess.run(["git", "-C", repo_path, "push", "origin", "main"], check=True)
|
|
@@ -570,23 +570,33 @@ def check_system_resources():
|
|
| 570 |
memory_usage = memory.percent
|
| 571 |
if cpu_usage >= 90 or memory_usage >= 95:
|
| 572 |
print("占用过高")
|
|
|
|
| 573 |
response = create_space(1)
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
create_space(3,"
|
| 580 |
-
create_space(3,"
|
| 581 |
-
create_space(3,"
|
| 582 |
-
create_space(3,"
|
| 583 |
-
create_space(3,"
|
| 584 |
-
create_space(3,"
|
| 585 |
-
create_space(3,"
|
| 586 |
-
create_space(3,"
|
| 587 |
-
create_space(3,"
|
| 588 |
-
create_space(3,"
|
| 589 |
-
create_space(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 591 |
# print(result)
|
| 592 |
else:
|
|
@@ -610,25 +620,32 @@ if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('
|
|
| 610 |
response = create_space(2)
|
| 611 |
print(response)
|
| 612 |
time.sleep(20)#21600 = 6小时
|
| 613 |
-
|
| 614 |
response = create_space(1)
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
create_space(3,"
|
| 621 |
-
create_space(3,"
|
| 622 |
-
create_space(3,"
|
| 623 |
-
create_space(3,"
|
| 624 |
-
create_space(3,"
|
| 625 |
-
create_space(3,"
|
| 626 |
-
create_space(3,"
|
| 627 |
-
create_space(3,"
|
| 628 |
-
create_space(3,"
|
| 629 |
-
create_space(3,"
|
| 630 |
-
create_space(
|
| 631 |
-
create_space(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}启动结束")
|
| 633 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 634 |
# print(result)
|
|
|
|
| 121 |
return response.json()
|
| 122 |
except Exception:
|
| 123 |
return {"status_code": response.status_code, "text": response.text}
|
| 124 |
+
|
| 125 |
+
def create_space(type,key = "", value = "",name = ""):
|
| 126 |
if type == 1:
|
| 127 |
# 创建spaces
|
| 128 |
url = "https://huggingface.co/api/repos/create"
|
|
|
|
| 130 |
"Content-Type": "application/json",
|
| 131 |
"Authorization": f"Bearer {HF_TOKON2}"
|
| 132 |
}
|
| 133 |
+
name = random_name()
|
| 134 |
payload = {
|
| 135 |
+
"name": name,
|
| 136 |
"type": "space",
|
| 137 |
"private": True,
|
| 138 |
"sleepTimeSeconds": 172800,
|
|
|
|
| 157 |
return response.text
|
| 158 |
if type == 3:
|
| 159 |
# 创建spaces 变量
|
| 160 |
+
url = f"https://huggingface.co/api/spaces/{HF_USER2}/{name}/secrets"
|
| 161 |
headers = {
|
| 162 |
"Content-Type": "application/json",
|
| 163 |
"Authorization": f"Bearer {HF_TOKON2}"
|
|
|
|
| 170 |
response = requests.post(url, headers=headers, json=payload)
|
| 171 |
return response.text
|
| 172 |
if type == 4:
|
| 173 |
+
file_path = f"/data/{name}/Dockerfile"
|
| 174 |
os.system("rm -rf {HF_SPACES_NAME}")
|
| 175 |
+
git = f"git clone https://{HF_USER2}:{HF_TOKON2}@huggingface.co/spaces/{HF_USER2}/{name}"
|
| 176 |
url = "https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile"
|
| 177 |
print(git)
|
| 178 |
os.system(git)
|
| 179 |
os.system(f'git config --global user.email "{HF_EMAIL2}"')
|
| 180 |
os.system(f'git config --global user.name "{HF_USER2}"')
|
| 181 |
+
os.chdir(f'/data/{name}')
|
| 182 |
time.sleep(3)
|
| 183 |
# 如果文件已存在,先删除
|
| 184 |
if os.path.exists(file_path):
|
|
|
|
| 197 |
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}下载Dockerfile下载失败,状态码: {response.status_code}")
|
| 198 |
|
| 199 |
# os.system(f"wget -O '/data/{tmp_name}/Dockerfile' https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile")
|
| 200 |
+
repo_path = f"/data/{name}"
|
| 201 |
subprocess.run(["git", "-C", repo_path, "add", "."], check=True)
|
| 202 |
subprocess.run(["git", "-C", repo_path, "commit", "-m", commit_message], check=True)
|
| 203 |
subprocess.run(["git", "-C", repo_path, "push", "origin", "main"], check=True)
|
|
|
|
| 570 |
memory_usage = memory.percent
|
| 571 |
if cpu_usage >= 90 or memory_usage >= 95:
|
| 572 |
print("占用过高")
|
| 573 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}CUP 内存占用过高,开始重启")
|
| 574 |
response = create_space(1)
|
| 575 |
+
full_name = response["name"]
|
| 576 |
+
tmp_name = full_name.split("/")[-1]
|
| 577 |
+
log = f"“原始创建Space返回:{response} name字段:{full_name} Space 名称{tmp_name}"
|
| 578 |
+
telegram_message(BOT_TOKEN, CHAT_ID, log)
|
| 579 |
+
print(log)
|
| 580 |
+
create_space(3,"BACKUP_TIME",BACKUP_TIME,tmp_name)
|
| 581 |
+
create_space(3,"HF_USER1",HF_USER1,tmp_name)
|
| 582 |
+
create_space(3,"HF_REPO",HF_REPO,tmp_name)
|
| 583 |
+
create_space(3,"HF_EMAIL",HF_EMAIL,tmp_name)
|
| 584 |
+
create_space(3,"HF_TOKEN1",HF_TOKEN1,tmp_name)
|
| 585 |
+
create_space(3,"HF_USER2",HF_USER2,tmp_name)
|
| 586 |
+
create_space(3,"HF_EMAIL2",HF_EMAIL2,tmp_name)
|
| 587 |
+
create_space(3,"HF_ID",tmp_name,tmp_name)
|
| 588 |
+
create_space(3,"HF_TOKON2",HF_TOKON2,tmp_name)
|
| 589 |
+
create_space(3,"UUID",UUID,tmp_name)
|
| 590 |
+
create_space(3,"N_SERVER","z.282820.xyz:443",tmp_name)
|
| 591 |
+
create_space(3,"CHAT_ID",CHAT_ID,tmp_name)
|
| 592 |
+
create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
|
| 593 |
+
create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
|
| 594 |
+
time.sleep(2)
|
| 595 |
+
create_space(4,"","",tmp_name)
|
| 596 |
+
time.sleep(2)
|
| 597 |
+
result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
|
| 598 |
+
print(f"{tmp_name}重启结果:",result)
|
| 599 |
+
|
| 600 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 601 |
# print(result)
|
| 602 |
else:
|
|
|
|
| 620 |
response = create_space(2)
|
| 621 |
print(response)
|
| 622 |
time.sleep(20)#21600 = 6小时
|
| 623 |
+
github(2)
|
| 624 |
response = create_space(1)
|
| 625 |
+
full_name = response["name"]
|
| 626 |
+
tmp_name = full_name.split("/")[-1]
|
| 627 |
+
log = f"“原始创建Space返回:{response} name字段:{full_name} Space 名称{tmp_name}"
|
| 628 |
+
telegram_message(BOT_TOKEN, CHAT_ID, log)
|
| 629 |
+
print(log)
|
| 630 |
+
create_space(3,"BACKUP_TIME",BACKUP_TIME,tmp_name)
|
| 631 |
+
create_space(3,"HF_USER1",HF_USER1,tmp_name)
|
| 632 |
+
create_space(3,"HF_REPO",HF_REPO,tmp_name)
|
| 633 |
+
create_space(3,"HF_EMAIL",HF_EMAIL,tmp_name)
|
| 634 |
+
create_space(3,"HF_TOKEN1",HF_TOKEN1,tmp_name)
|
| 635 |
+
create_space(3,"HF_USER2",HF_USER2,tmp_name)
|
| 636 |
+
create_space(3,"HF_EMAIL2",HF_EMAIL2,tmp_name)
|
| 637 |
+
create_space(3,"HF_ID",tmp_name,tmp_name)
|
| 638 |
+
create_space(3,"HF_TOKON2",HF_TOKON2,tmp_name)
|
| 639 |
+
create_space(3,"UUID",UUID,tmp_name)
|
| 640 |
+
create_space(3,"N_SERVER","z.282820.xyz:443",tmp_name)
|
| 641 |
+
create_space(3,"CHAT_ID",CHAT_ID,tmp_name)
|
| 642 |
+
create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
|
| 643 |
+
create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
|
| 644 |
+
time.sleep(2)
|
| 645 |
+
create_space(4,"","",tmp_name)
|
| 646 |
+
time.sleep(2)
|
| 647 |
+
result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
|
| 648 |
+
print(f"{tmp_name}重启结果:",result)
|
| 649 |
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}启动结束")
|
| 650 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 651 |
# print(result)
|