Spaces:
Paused
Paused
Upload 4 files
Browse files- app.py +10 -0
- templates/login.html +1 -1
app.py
CHANGED
|
@@ -1098,12 +1098,19 @@ def get_space_url():
|
|
| 1098 |
space_id = os.environ.get("SPACE_ID")
|
| 1099 |
if space_id:
|
| 1100 |
username, space_name = space_id.split("/")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1101 |
return f"https://{username}-{space_name}.hf.space"
|
| 1102 |
|
| 1103 |
# 如果以上都不存在,尝试从单独的用户名和空间名构建
|
| 1104 |
username = os.environ.get("SPACE_USERNAME")
|
| 1105 |
space_name = os.environ.get("SPACE_NAME")
|
| 1106 |
if username and space_name:
|
|
|
|
|
|
|
|
|
|
| 1107 |
return f"https://{username}-{space_name}.hf.space"
|
| 1108 |
|
| 1109 |
# 默认返回None
|
|
@@ -1111,6 +1118,9 @@ def get_space_url():
|
|
| 1111 |
|
| 1112 |
# 获取空间URL
|
| 1113 |
SPACE_URL = get_space_url()
|
|
|
|
|
|
|
|
|
|
| 1114 |
|
| 1115 |
|
| 1116 |
if __name__ == "__main__":
|
|
|
|
| 1098 |
space_id = os.environ.get("SPACE_ID")
|
| 1099 |
if space_id:
|
| 1100 |
username, space_name = space_id.split("/")
|
| 1101 |
+
# 将空间名称中的下划线替换为连字符
|
| 1102 |
+
# 注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)
|
| 1103 |
+
# 例如:"abacus_chat_proxy" 会变成 "abacus-chat-proxy"
|
| 1104 |
+
space_name = space_name.replace("_", "-")
|
| 1105 |
return f"https://{username}-{space_name}.hf.space"
|
| 1106 |
|
| 1107 |
# 如果以上都不存在,尝试从单独的用户名和空间名构建
|
| 1108 |
username = os.environ.get("SPACE_USERNAME")
|
| 1109 |
space_name = os.environ.get("SPACE_NAME")
|
| 1110 |
if username and space_name:
|
| 1111 |
+
# 将空间名称中的下划线替换为连字符
|
| 1112 |
+
# 同上,Hugging Face会自动进行此转换
|
| 1113 |
+
space_name = space_name.replace("_", "-")
|
| 1114 |
return f"https://{username}-{space_name}.hf.space"
|
| 1115 |
|
| 1116 |
# 默认返回None
|
|
|
|
| 1118 |
|
| 1119 |
# 获取空间URL
|
| 1120 |
SPACE_URL = get_space_url()
|
| 1121 |
+
if SPACE_URL:
|
| 1122 |
+
print(f"Space URL: {SPACE_URL}")
|
| 1123 |
+
print("注意:Hugging Face生成的URL会自动将空间名称中的下划线(_)替换为连字符(-)")
|
| 1124 |
|
| 1125 |
|
| 1126 |
if __name__ == "__main__":
|
templates/login.html
CHANGED
|
@@ -315,7 +315,7 @@
|
|
| 315 |
|
| 316 |
{% if space_url %}
|
| 317 |
<div class="space-info">
|
| 318 |
-
请访问 <a href="{{ space_url }}
|
| 319 |
</div>
|
| 320 |
{% endif %}
|
| 321 |
|
|
|
|
| 315 |
|
| 316 |
{% if space_url %}
|
| 317 |
<div class="space-info">
|
| 318 |
+
请访问 <a href="{{ space_url }}" target="_blank">{{ space_url }}</a> 查看使用情况
|
| 319 |
</div>
|
| 320 |
{% endif %}
|
| 321 |
|