Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import time
|
|
3 |
import logging
|
4 |
import requests
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
6 |
|
7 |
# 配置日志记录
|
8 |
logging.basicConfig(level=logging.INFO,
|
@@ -10,6 +11,8 @@ logging.basicConfig(level=logging.INFO,
|
|
10 |
|
11 |
API_ENDPOINT = "https://api.siliconflow.cn/v1/usage/credit_summary"
|
12 |
|
|
|
|
|
13 |
def get_credit_summary(api_key):
|
14 |
"""
|
15 |
使用 API 密钥获取额度信息。
|
@@ -54,17 +57,22 @@ scheduler = BackgroundScheduler()
|
|
54 |
# 添加定时任务,每小时执行一次 load_keys 函数
|
55 |
scheduler.add_job(load_keys, 'interval', hours=1)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
if __name__ == '__main__':
|
58 |
logging.info(f"===== Application Startup at {time.strftime('%Y-%m-%d %H:%M:%S')} =====")
|
59 |
-
try:
|
60 |
-
# 启动调度器
|
61 |
-
scheduler.start()
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
except (KeyboardInterrupt, SystemExit):
|
70 |
-
scheduler.shutdown()
|
|
|
3 |
import logging
|
4 |
import requests
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
6 |
+
from flask import Flask
|
7 |
|
8 |
# 配置日志记录
|
9 |
logging.basicConfig(level=logging.INFO,
|
|
|
11 |
|
12 |
API_ENDPOINT = "https://api.siliconflow.cn/v1/usage/credit_summary"
|
13 |
|
14 |
+
app = Flask(__name__)
|
15 |
+
|
16 |
def get_credit_summary(api_key):
|
17 |
"""
|
18 |
使用 API 密钥获取额度信息。
|
|
|
57 |
# 添加定时任务,每小时执行一次 load_keys 函数
|
58 |
scheduler.add_job(load_keys, 'interval', hours=1)
|
59 |
|
60 |
+
@app.route('/')
|
61 |
+
def index():
|
62 |
+
"""
|
63 |
+
处理根路由的访问请求。
|
64 |
+
"""
|
65 |
+
return "<h1>Welcome to SiliconFlow</h1>"
|
66 |
+
|
67 |
if __name__ == '__main__':
|
68 |
logging.info(f"===== Application Startup at {time.strftime('%Y-%m-%d %H:%M:%S')} =====")
|
|
|
|
|
|
|
69 |
|
70 |
+
# 启动调度器
|
71 |
+
scheduler.start()
|
72 |
+
|
73 |
+
# 手动触发一次 load_keys 任务
|
74 |
+
load_keys()
|
75 |
+
logging.info("首次加载 keys 已手动触发执行")
|
76 |
|
77 |
+
# 启动 Flask 应用,监听所有 IP 的 5000 端口
|
78 |
+
app.run(debug=False, host='0.0.0.0', port=5000)
|
|
|
|