Spaces:
Sleeping
Sleeping
端口
Browse files
app.py
CHANGED
|
@@ -1099,22 +1099,34 @@ def get_clipboard():
|
|
| 1099 |
return jsonify({"success": False, "message": f"服务器内部错误: {str(e)}"}), 500
|
| 1100 |
|
| 1101 |
if __name__ == '__main__':
|
| 1102 |
-
#
|
| 1103 |
import os
|
| 1104 |
-
|
| 1105 |
-
#
|
| 1106 |
-
|
| 1107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1108 |
local_ip = get_local_ip()
|
| 1109 |
print(f"Local IP Address: {local_ip}")
|
| 1110 |
print(f"Connect from your mobile device using: {local_ip}:{port}")
|
| 1111 |
-
|
| 1112 |
-
# 加载模型配置 (
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1120 |
socketio.run(app, host='0.0.0.0', port=port, allow_unsafe_werkzeug=True)
|
|
|
|
| 1099 |
return jsonify({"success": False, "message": f"服务器内部错误: {str(e)}"}), 500
|
| 1100 |
|
| 1101 |
if __name__ == '__main__':
|
| 1102 |
+
# 确保 os 库已经导入 (在文件顶部已有 `import os`)
|
| 1103 |
import os
|
| 1104 |
+
|
| 1105 |
+
# 优先从 Hugging Face 提供的 PORT 环境变量读取 (预期值 7860)。
|
| 1106 |
+
# 如果环境变量未设置,使用 7860 作为后备,而非 5000,以确保与 README.md 配置一致。
|
| 1107 |
+
port = int(os.environ.get('PORT', 7860))
|
| 1108 |
+
|
| 1109 |
+
# --- 确保旧的端口检测、硬编码 5000/5001 的逻辑已被彻底移除 ---
|
| 1110 |
+
|
| 1111 |
+
# 打印连接信息
|
| 1112 |
+
# 确保 get_local_ip() 函数在文件前面已经定义
|
| 1113 |
local_ip = get_local_ip()
|
| 1114 |
print(f"Local IP Address: {local_ip}")
|
| 1115 |
print(f"Connect from your mobile device using: {local_ip}:{port}")
|
| 1116 |
+
|
| 1117 |
+
# 加载模型配置 (保持不变,确保 ModelFactory 和 load_model_config() 可用)
|
| 1118 |
+
try:
|
| 1119 |
+
from models import ModelFactory # 确保 ModelFactory 已在顶部导入
|
| 1120 |
+
except ImportError:
|
| 1121 |
+
pass
|
| 1122 |
+
|
| 1123 |
+
try:
|
| 1124 |
+
model_config = load_model_config()
|
| 1125 |
+
if hasattr(ModelFactory, 'update_model_capabilities'):
|
| 1126 |
+
ModelFactory.update_model_capabilities(model_config)
|
| 1127 |
+
print("已加载模型配置信息")
|
| 1128 |
+
except Exception as e:
|
| 1129 |
+
print(f"警告:模型配置加载失败: {e}")
|
| 1130 |
+
|
| 1131 |
+
# 运行应用,并绑定到 0.0.0.0 和从环境变量读取的端口 (7860)
|
| 1132 |
socketio.run(app, host='0.0.0.0', port=port, allow_unsafe_werkzeug=True)
|