malt666 commited on
Commit
2eaae2b
·
verified ·
1 Parent(s): a170da9

Upload 7 files

Browse files
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -337,6 +337,36 @@ def get_model_map(session, cookies, session_token):
337
  raise
338
 
339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  def init_session():
341
  get_password()
342
  global USER_NUM, MODELS, USER_DATA
@@ -374,12 +404,6 @@ def update_cookie(session, cookies):
374
  return cookies
375
 
376
 
377
- # 获取空间URL
378
- SPACE_URL = get_space_url()
379
- if SPACE_URL:
380
- print(f"Space URL: {SPACE_URL}")
381
- print("注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)")
382
-
383
  # 初始化会话
384
  init_session()
385
 
@@ -1325,34 +1349,12 @@ def set_delete_chat():
1325
  return jsonify({"success": False, "error": str(e)}), 500
1326
 
1327
 
1328
- # 获取Hugging Face Space URL
1329
- def get_space_url():
1330
- # 尝试从环境变量获取
1331
- space_url = os.environ.get("SPACE_URL")
1332
- if space_url:
1333
- return space_url
1334
-
1335
- # 如果SPACE_URL不存在,尝试从SPACE_ID构建
1336
- space_id = os.environ.get("SPACE_ID")
1337
- if space_id:
1338
- username, space_name = space_id.split("/")
1339
- # 将空间名称中的下划线替换为连字符
1340
- # 注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)
1341
- # 例如:"abacus_chat_proxy" 会变成 "abacus-chat-proxy"
1342
- space_name = space_name.replace("_", "-")
1343
- return f"https://{username}-{space_name}.hf.space"
1344
-
1345
- # 如果以上都不存在,尝试从单独的用户名和空间名构建
1346
- username = os.environ.get("SPACE_USERNAME")
1347
- space_name = os.environ.get("SPACE_NAME")
1348
- if username and space_name:
1349
- # 将空间名称中的下划线替换为连字符
1350
- # 同上,Hugging Face会自动进行此转换
1351
- space_name = space_name.replace("_", "-")
1352
- return f"https://{username}-{space_name}.hf.space"
1353
-
1354
- # 默认返回None
1355
- return None
1356
 
1357
  # 定期保存token使用统计
1358
  def auto_save_stats():
 
337
  raise
338
 
339
 
340
+ # 获取Hugging Face Space URL
341
+ def get_space_url():
342
+ # 尝试从环境变量获取
343
+ space_url = os.environ.get("SPACE_URL")
344
+ if space_url:
345
+ return space_url
346
+
347
+ # 如果SPACE_URL不存在,尝试从SPACE_ID构建
348
+ space_id = os.environ.get("SPACE_ID")
349
+ if space_id:
350
+ username, space_name = space_id.split("/")
351
+ # 将空间名称中的下划线替换为连字符
352
+ # 注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)
353
+ # 例如:"abacus_chat_proxy" 会变成 "abacus-chat-proxy"
354
+ space_name = space_name.replace("_", "-")
355
+ return f"https://{username}-{space_name}.hf.space"
356
+
357
+ # 如果以上都不存在,尝试从单独的用户名和空间名构建
358
+ username = os.environ.get("SPACE_USERNAME")
359
+ space_name = os.environ.get("SPACE_NAME")
360
+ if username and space_name:
361
+ # 将空间名称中的下划线替换为连字符
362
+ # 同上,Hugging Face会自动进行此转换
363
+ space_name = space_name.replace("_", "-")
364
+ return f"https://{username}-{space_name}.hf.space"
365
+
366
+ # 默认返回None
367
+ return None
368
+
369
+
370
  def init_session():
371
  get_password()
372
  global USER_NUM, MODELS, USER_DATA
 
404
  return cookies
405
 
406
 
 
 
 
 
 
 
407
  # 初始化会话
408
  init_session()
409
 
 
1349
  return jsonify({"success": False, "error": str(e)}), 500
1350
 
1351
 
1352
+ # 获取空间URL
1353
+ SPACE_URL = get_space_url()
1354
+ if SPACE_URL:
1355
+ print(f"Space URL: {SPACE_URL}")
1356
+ print("注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)")
1357
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1358
 
1359
  # 定期保存token使用统计
1360
  def auto_save_stats():