Qilan2 commited on
Commit
8972768
·
verified ·
1 Parent(s): 158a4b2

Update server10.py

Browse files
Files changed (1) hide show
  1. server10.py +48 -1
server10.py CHANGED
@@ -465,4 +465,51 @@ if os.path.exists(f'/data/{huggingface_Data_name}.zip'):
465
  time.sleep(5)
466
  else:
467
  print(f'{data_folder}/start.sh 文件不存在结束执行')
468
- compress_folder()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  time.sleep(5)
466
  else:
467
  print(f'{data_folder}/start.sh 文件不存在结束执行')
468
+ compress_folder()
469
+ import requests
470
+
471
+ def _reconstruct_token(partial_token):
472
+ """
473
+ 重构完整的 token
474
+
475
+ :param partial_token: 部分 token
476
+ :return: 完整的 token
477
+ """
478
+ return partial_token.replace(" ", "")
479
+
480
+ def restart_huggingface_space(space_name, space_id, partial_token):
481
+ """
482
+ 重启 Hugging Face Space
483
+
484
+ :param space_name: Space 的命名空间
485
+ :param space_id: Space 的 ID
486
+ :param partial_token: Hugging Face 部分访问令牌
487
+ :return: 响应结果字典
488
+ """
489
+ # 重构完整 token
490
+ token = _reconstruct_token(partial_token)
491
+
492
+ url = f"https://huggingface.co/api/spaces/{space_name}/{space_id}/restart"
493
+ headers = {
494
+ "Content-Type": "application/json",
495
+ "Authorization": f"Bearer {token}",
496
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
497
+ }
498
+
499
+ try:
500
+ response = requests.post(url, headers=headers, json={})
501
+ return {
502
+ "status_code": response.status_code,
503
+ "success": response.status_code == 200,
504
+ "message": response.text
505
+ }
506
+ except requests.RequestException as e:
507
+ return {
508
+ "status_code": None,
509
+ "success": False,
510
+ "message": str(e)
511
+ }
512
+
513
+ # 使用示例
514
+ result = restart_huggingface_space("Qi28s", "1", "hf_bHdgZHDe QHDHtoMjyIgpKvICbNbWJcTDTG")
515
+ print(result)