Update ff1.py
Browse files
ff1.py
CHANGED
|
@@ -90,8 +90,10 @@ def nv1():
|
|
| 90 |
os.system('./f1 -c ./config.yaml')
|
| 91 |
threading.Thread(target=nv1, daemon=True).start()
|
| 92 |
threading.Thread(target=cf, daemon=True).start()
|
|
|
|
| 93 |
def random_name(length=8):
|
| 94 |
-
return ''.join(random.choices(string.ascii_lowercase
|
|
|
|
| 95 |
def update_value(data: dict, key: str, new_value: str) -> dict:
|
| 96 |
if key in data:
|
| 97 |
data[key] = new_value
|
|
@@ -119,8 +121,8 @@ def telegram_message(bot_token: str, chat_id: str, message: str):
|
|
| 119 |
return response.json()
|
| 120 |
except Exception:
|
| 121 |
return {"status_code": response.status_code, "text": response.text}
|
| 122 |
-
|
| 123 |
-
def create_space(type,key = "", value = ""):
|
| 124 |
if type == 1:
|
| 125 |
# 创建spaces
|
| 126 |
url = "https://huggingface.co/api/repos/create"
|
|
@@ -128,9 +130,9 @@ def create_space(type,key = "", value = ""):
|
|
| 128 |
"Content-Type": "application/json",
|
| 129 |
"Authorization": f"Bearer {HF_TOKON2}"
|
| 130 |
}
|
| 131 |
-
|
| 132 |
payload = {
|
| 133 |
-
"name":
|
| 134 |
"type": "space",
|
| 135 |
"private": True,
|
| 136 |
"sleepTimeSeconds": 172800,
|
|
@@ -155,7 +157,7 @@ def create_space(type,key = "", value = ""):
|
|
| 155 |
return response.text
|
| 156 |
if type == 3:
|
| 157 |
# 创建spaces 变量
|
| 158 |
-
url = f"https://huggingface.co/api/spaces/{HF_USER2}/{
|
| 159 |
headers = {
|
| 160 |
"Content-Type": "application/json",
|
| 161 |
"Authorization": f"Bearer {HF_TOKON2}"
|
|
@@ -168,15 +170,15 @@ def create_space(type,key = "", value = ""):
|
|
| 168 |
response = requests.post(url, headers=headers, json=payload)
|
| 169 |
return response.text
|
| 170 |
if type == 4:
|
| 171 |
-
file_path = f"/data/{
|
| 172 |
os.system("rm -rf {HF_SPACES_NAME}")
|
| 173 |
-
git = f"git clone https://{HF_USER2}:{HF_TOKON2}@huggingface.co/spaces/{HF_USER2}/{
|
| 174 |
url = "https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile"
|
| 175 |
print(git)
|
| 176 |
os.system(git)
|
| 177 |
os.system(f'git config --global user.email "{HF_EMAIL2}"')
|
| 178 |
os.system(f'git config --global user.name "{HF_USER2}"')
|
| 179 |
-
os.chdir(f'/data/{
|
| 180 |
time.sleep(3)
|
| 181 |
# 如果文件已存在,先删除
|
| 182 |
if os.path.exists(file_path):
|
|
@@ -189,12 +191,23 @@ def create_space(type,key = "", value = ""):
|
|
| 189 |
with open(file_path, "wb") as f:
|
| 190 |
f.write(response.content)
|
| 191 |
print("下载完成 ✅")
|
|
|
|
| 192 |
else:
|
| 193 |
print(f"下载失败,状态码: {response.status_code}")
|
|
|
|
|
|
|
| 194 |
# os.system(f"wget -O '/data/{tmp_name}/Dockerfile' https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile")
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
def get_latest_local_package(directory, pattern='*.tar.gz'):
|
| 199 |
try:
|
| 200 |
# 构建完整的搜索路径
|
|
@@ -557,23 +570,33 @@ def check_system_resources():
|
|
| 557 |
memory_usage = memory.percent
|
| 558 |
if cpu_usage >= 90 or memory_usage >= 95:
|
| 559 |
print("占用过高")
|
|
|
|
| 560 |
response = create_space(1)
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
create_space(3,"
|
| 567 |
-
create_space(3,"
|
| 568 |
-
create_space(3,"
|
| 569 |
-
create_space(3,"
|
| 570 |
-
create_space(3,"
|
| 571 |
-
create_space(3,"
|
| 572 |
-
create_space(3,"
|
| 573 |
-
create_space(3,"
|
| 574 |
-
create_space(3,"
|
| 575 |
-
create_space(3,"
|
| 576 |
-
create_space(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 578 |
# print(result)
|
| 579 |
else:
|
|
@@ -591,33 +614,41 @@ github(1)
|
|
| 591 |
|
| 592 |
if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('/data/ff/.mozilla/firefox/profiles.ini'):
|
| 593 |
threading.Thread(target=repeat_task, daemon=True).start()
|
| 594 |
-
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}开始启动")
|
| 595 |
while True:
|
| 596 |
print("检测到Firefox配置,启动定期重启循环...")
|
| 597 |
response = create_space(2)
|
| 598 |
print(response)
|
| 599 |
-
time.sleep(
|
| 600 |
github(2)
|
| 601 |
response = create_space(1)
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
create_space(3,"
|
| 608 |
-
create_space(3,"
|
| 609 |
-
create_space(3,"
|
| 610 |
-
create_space(3,"
|
| 611 |
-
create_space(3,"
|
| 612 |
-
create_space(3,"
|
| 613 |
-
create_space(3,"
|
| 614 |
-
create_space(3,"
|
| 615 |
-
create_space(3,"
|
| 616 |
-
create_space(3,"
|
| 617 |
-
create_space(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}启动结束")
|
| 619 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 620 |
# print(result)
|
| 621 |
-
break
|
| 622 |
# github(2)
|
| 623 |
# nv1_agent()
|
|
|
|
| 90 |
os.system('./f1 -c ./config.yaml')
|
| 91 |
threading.Thread(target=nv1, daemon=True).start()
|
| 92 |
threading.Thread(target=cf, daemon=True).start()
|
| 93 |
+
|
| 94 |
def random_name(length=8):
|
| 95 |
+
return ''.join(random.choices(string.ascii_lowercase, k=length))
|
| 96 |
+
|
| 97 |
def update_value(data: dict, key: str, new_value: str) -> dict:
|
| 98 |
if key in data:
|
| 99 |
data[key] = new_value
|
|
|
|
| 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} /data/{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):
|
|
|
|
| 191 |
with open(file_path, "wb") as f:
|
| 192 |
f.write(response.content)
|
| 193 |
print("下载完成 ✅")
|
| 194 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}下载Dockerfile 结果:下载完成 ✅")
|
| 195 |
else:
|
| 196 |
print(f"下载失败,状态码: {response.status_code}")
|
| 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", "0"], check=True)
|
| 203 |
+
subprocess.run(["git", "-C", repo_path, "push", "origin", "main"], check=True)
|
| 204 |
+
# os.system('git add .')
|
| 205 |
+
# os.system('git commit -m "0"')
|
| 206 |
+
# push_result = os.system('git push origin main')
|
| 207 |
+
# if push_result != 0:
|
| 208 |
+
# print("推送失败,可能有冲突,尝试拉取并合并...")
|
| 209 |
+
# os.system('git pull origin main --rebase')
|
| 210 |
+
# os.system('git push origin main')
|
| 211 |
def get_latest_local_package(directory, pattern='*.tar.gz'):
|
| 212 |
try:
|
| 213 |
# 构建完整的搜索路径
|
|
|
|
| 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:
|
|
|
|
| 614 |
|
| 615 |
if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('/data/ff/.mozilla/firefox/profiles.ini'):
|
| 616 |
threading.Thread(target=repeat_task, daemon=True).start()
|
| 617 |
+
# telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}开始启动")
|
| 618 |
while True:
|
| 619 |
print("检测到Firefox配置,启动定期重启循环...")
|
| 620 |
response = create_space(2)
|
| 621 |
print(response)
|
| 622 |
+
time.sleep(21600)#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)
|
| 652 |
+
# break
|
| 653 |
# github(2)
|
| 654 |
# nv1_agent()
|