Spaces:
Paused
Paused
Upload 3 files
Browse files- app.py +74 -109
- templates/dashboard.html +33 -9
app.py
CHANGED
|
@@ -55,20 +55,22 @@ total_tokens = {
|
|
| 55 |
"total": 0 # 总token统计
|
| 56 |
}
|
| 57 |
|
| 58 |
-
# 计算点信息
|
| 59 |
-
compute_points =
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
}
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
# 记录启动时间
|
|
@@ -821,105 +823,68 @@ def update_model_stats(model, prompt_tokens, completion_tokens):
|
|
| 821 |
|
| 822 |
# 获取计算点信息
|
| 823 |
def get_compute_points():
|
| 824 |
-
global compute_points,
|
| 825 |
|
| 826 |
-
|
| 827 |
-
|
| 828 |
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
session, cookies, session_token, _, _ = USER_DATA[0]
|
| 832 |
-
|
| 833 |
-
# 检查token是否有效
|
| 834 |
-
if is_token_expired(session_token):
|
| 835 |
-
session_token = refresh_token(session, cookies)
|
| 836 |
-
if not session_token:
|
| 837 |
-
print("刷新token失败,无法获取计算点信息")
|
| 838 |
-
return
|
| 839 |
-
USER_DATA[0] = (session, cookies, session_token, USER_DATA[0][3], USER_DATA[0][4])
|
| 840 |
-
|
| 841 |
-
headers = {
|
| 842 |
-
"accept": "application/json, text/plain, */*",
|
| 843 |
-
"accept-language": "zh-CN,zh;q=0.9",
|
| 844 |
-
"baggage": f"sentry-environment=production,sentry-release=93da8385541a6ce339b1f41b0c94428c70657e22,sentry-public_key=3476ea6df1585dd10e92cdae3a66ff49,sentry-trace_id={TRACE_ID}",
|
| 845 |
-
"reai-ui": "1",
|
| 846 |
-
"sec-ch-ua": "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"",
|
| 847 |
-
"sec-ch-ua-mobile": "?0",
|
| 848 |
-
"sec-ch-ua-platform": "\"Windows\"",
|
| 849 |
-
"sec-fetch-dest": "empty",
|
| 850 |
-
"sec-fetch-mode": "cors",
|
| 851 |
-
"sec-fetch-site": "same-origin",
|
| 852 |
-
"sentry-trace": SENTRY_TRACE,
|
| 853 |
-
"session-token": session_token,
|
| 854 |
-
"x-abacus-org-host": "apps",
|
| 855 |
-
"cookie": cookies
|
| 856 |
-
}
|
| 857 |
-
|
| 858 |
-
response = session.get(
|
| 859 |
-
COMPUTE_POINTS_URL,
|
| 860 |
-
headers=headers
|
| 861 |
-
)
|
| 862 |
-
|
| 863 |
-
if response.status_code == 200:
|
| 864 |
-
result = response.json()
|
| 865 |
-
if result.get("success") and "result" in result:
|
| 866 |
-
data = result["result"]
|
| 867 |
-
compute_points["left"] = data.get("computePointsLeft", 0)
|
| 868 |
-
compute_points["total"] = data.get("totalComputePoints", 0)
|
| 869 |
-
compute_points["used"] = compute_points["total"] - compute_points["left"]
|
| 870 |
-
compute_points["percentage"] = round((compute_points["used"] / compute_points["total"]) * 100, 2) if compute_points["total"] > 0 else 0
|
| 871 |
-
compute_points["last_update"] = datetime.now()
|
| 872 |
-
print(f"计算点信息更新成功: 剩余 {compute_points['left']}, 总计 {compute_points['total']}")
|
| 873 |
-
|
| 874 |
-
# 获取计算点使用日志
|
| 875 |
-
get_compute_points_log(session, cookies, session_token)
|
| 876 |
-
else:
|
| 877 |
-
print(f"获取计算点信息失败: {result.get('error', '未知错误')}")
|
| 878 |
-
else:
|
| 879 |
-
print(f"获取计算点信息失败,状态码: {response.status_code}")
|
| 880 |
-
except Exception as e:
|
| 881 |
-
print(f"获取计算点信息异常: {e}")
|
| 882 |
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
try:
|
| 888 |
-
headers = {
|
| 889 |
-
"accept": "application/json, text/plain, */*",
|
| 890 |
-
"accept-language": "zh-CN,zh;q=0.9",
|
| 891 |
-
"content-type": "application/json",
|
| 892 |
-
"reai-ui": "1",
|
| 893 |
-
"sec-ch-ua": "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"",
|
| 894 |
-
"sec-ch-ua-mobile": "?0",
|
| 895 |
-
"sec-ch-ua-platform": "\"Windows\"",
|
| 896 |
-
"sec-fetch-dest": "empty",
|
| 897 |
-
"sec-fetch-mode": "cors",
|
| 898 |
-
"sec-fetch-site": "same-site",
|
| 899 |
-
"session-token": session_token,
|
| 900 |
-
"x-abacus-org-host": "apps",
|
| 901 |
-
"cookie": cookies
|
| 902 |
}
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 923 |
|
| 924 |
|
| 925 |
# 添加登录相关路由
|
|
|
|
| 55 |
"total": 0 # 总token统计
|
| 56 |
}
|
| 57 |
|
| 58 |
+
# 计算点信息 (现在是列表)
|
| 59 |
+
compute_points = []
|
| 60 |
+
# {
|
| 61 |
+
# "left": 0, # 剩余计算点
|
| 62 |
+
# "total": 0, # 总计算点
|
| 63 |
+
# "used": 0, # 已使用计算点
|
| 64 |
+
# "percentage": 0, # 使用百分比
|
| 65 |
+
# "last_update": None # 最后更新时间
|
| 66 |
+
# }
|
| 67 |
+
|
| 68 |
+
# 计算点使用日志 (现在是列表)
|
| 69 |
+
compute_points_log = []
|
| 70 |
+
# {
|
| 71 |
+
# "columns": {}, # 列名
|
| 72 |
+
# "log": [] # 日志数据
|
| 73 |
+
# }
|
| 74 |
|
| 75 |
|
| 76 |
# 记录启动时间
|
|
|
|
| 823 |
|
| 824 |
# 获取计算点信息
|
| 825 |
def get_compute_points():
|
| 826 |
+
global compute_points, compute_points_log
|
| 827 |
|
| 828 |
+
# 限制只获取前两个用户的数据
|
| 829 |
+
users_to_fetch = USER_DATA[:2]
|
| 830 |
|
| 831 |
+
new_compute_points = []
|
| 832 |
+
new_compute_points_log = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 833 |
|
| 834 |
+
for user_index, user_config in enumerate(users_to_fetch):
|
| 835 |
+
user_compute_points = {
|
| 836 |
+
"left": 0, "total": 0, "used": 0, "percentage": 0, "last_update": None, "error": None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
}
|
| 838 |
+
user_compute_points_log = {
|
| 839 |
+
"columns": {}, "log": [], "error": None
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
try:
|
| 843 |
+
headers = {
|
| 844 |
+
"Cookie": user_config["cookies"],
|
| 845 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
# 获取计算点信息
|
| 849 |
+
compute_url = "https://abacus.art/api/trpc/user.getComputePoints"
|
| 850 |
+
response = requests.get(compute_url, headers=headers)
|
| 851 |
+
response.raise_for_status()
|
| 852 |
+
data = response.json()
|
| 853 |
+
|
| 854 |
+
points_data = data.get("result", {}).get("data", {})
|
| 855 |
+
user_compute_points["left"] = points_data.get("left", 0)
|
| 856 |
+
user_compute_points["total"] = points_data.get("total", 0)
|
| 857 |
+
user_compute_points["used"] = points_data.get("used", 0)
|
| 858 |
+
user_compute_points["percentage"] = points_data.get("percentage", 0)
|
| 859 |
+
user_compute_points["last_update"] = datetime.now()
|
| 860 |
+
|
| 861 |
+
# 获取计算点使用日志
|
| 862 |
+
log_url = "https://abacus.art/api/trpc/user.getComputePointsLog?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%7D"
|
| 863 |
+
response = requests.get(log_url, headers=headers)
|
| 864 |
+
response.raise_for_status()
|
| 865 |
+
log_data = response.json()
|
| 866 |
+
|
| 867 |
+
log_result = log_data[0].get("result", {}).get("data", {}).get("json", {})
|
| 868 |
+
user_compute_points_log["columns"] = log_result.get("columns", {})
|
| 869 |
+
user_compute_points_log["log"] = log_result.get("log", [])
|
| 870 |
+
|
| 871 |
+
except requests.exceptions.RequestException as e:
|
| 872 |
+
error_message = f"用户 {user_index + 1} 获取计算点信息异常: {e}"
|
| 873 |
+
print(error_message)
|
| 874 |
+
user_compute_points["error"] = str(e)
|
| 875 |
+
user_compute_points_log["error"] = str(e)
|
| 876 |
+
except Exception as e:
|
| 877 |
+
error_message = f"用户 {user_index + 1} 处理计算点信息时发生未知错误: {e}"
|
| 878 |
+
print(error_message)
|
| 879 |
+
user_compute_points["error"] = str(e)
|
| 880 |
+
user_compute_points_log["error"] = str(e)
|
| 881 |
+
|
| 882 |
+
new_compute_points.append(user_compute_points)
|
| 883 |
+
new_compute_points_log.append(user_compute_points_log)
|
| 884 |
+
|
| 885 |
+
# 更新全局变量
|
| 886 |
+
compute_points = new_compute_points
|
| 887 |
+
compute_points_log = new_compute_points_log
|
| 888 |
|
| 889 |
|
| 890 |
# 添加登录相关路由
|
templates/dashboard.html
CHANGED
|
@@ -550,43 +550,67 @@
|
|
| 550 |
</div>
|
| 551 |
|
| 552 |
<div class="grid">
|
|
|
|
|
|
|
| 553 |
<div class="card">
|
| 554 |
<div class="card-header">
|
| 555 |
<h2 class="card-title">
|
| 556 |
<span class="card-icon">💰</span>
|
| 557 |
-
计算点信息
|
| 558 |
</h2>
|
| 559 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
<div class="status-item">
|
| 561 |
<span class="status-label">总计算点</span>
|
| 562 |
-
<span class="status-value compute-points">{{
|
| 563 |
</div>
|
| 564 |
<div class="status-item">
|
| 565 |
<span class="status-label">已使用</span>
|
| 566 |
-
<span class="status-value compute-points">{{
|
| 567 |
</div>
|
| 568 |
<div class="status-item">
|
| 569 |
<span class="status-label">剩余</span>
|
| 570 |
-
<span class="status-value compute-points">{{
|
| 571 |
</div>
|
| 572 |
<div class="status-item">
|
| 573 |
<span class="status-label">使用比例</span>
|
| 574 |
<div style="width: 100%; text-align: right;">
|
| 575 |
-
<span class="status-value compute-points {% if
|
| 576 |
-
{{
|
| 577 |
</span>
|
| 578 |
<div class="progress-container">
|
| 579 |
-
<div class="progress-bar {% if
|
| 580 |
</div>
|
| 581 |
</div>
|
| 582 |
</div>
|
| 583 |
-
{% if
|
| 584 |
<div class="status-item">
|
| 585 |
<span class="status-label">最后更新时间</span>
|
| 586 |
-
<span class="status-value">{{
|
| 587 |
</div>
|
| 588 |
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
</div>
|
|
|
|
| 590 |
|
| 591 |
<div class="card">
|
| 592 |
<div class="card-header">
|
|
|
|
| 550 |
</div>
|
| 551 |
|
| 552 |
<div class="grid">
|
| 553 |
+
{% if compute_points %}
|
| 554 |
+
{% for user_points in compute_points %}
|
| 555 |
<div class="card">
|
| 556 |
<div class="card-header">
|
| 557 |
<h2 class="card-title">
|
| 558 |
<span class="card-icon">💰</span>
|
| 559 |
+
用户 {{ loop.index }} 计算点信息
|
| 560 |
</h2>
|
| 561 |
</div>
|
| 562 |
+
{% if user_points.error %}
|
| 563 |
+
<div class="status-item">
|
| 564 |
+
<span class="status-label">错误</span>
|
| 565 |
+
<span class="status-value danger">获取失败: {{ user_points.error }}</span>
|
| 566 |
+
</div>
|
| 567 |
+
{% else %}
|
| 568 |
<div class="status-item">
|
| 569 |
<span class="status-label">总计算点</span>
|
| 570 |
+
<span class="status-value compute-points">{{ user_points.total|int }}</span>
|
| 571 |
</div>
|
| 572 |
<div class="status-item">
|
| 573 |
<span class="status-label">已使用</span>
|
| 574 |
+
<span class="status-value compute-points">{{ user_points.used|int }}</span>
|
| 575 |
</div>
|
| 576 |
<div class="status-item">
|
| 577 |
<span class="status-label">剩余</span>
|
| 578 |
+
<span class="status-value compute-points">{{ user_points.left|int }}</span>
|
| 579 |
</div>
|
| 580 |
<div class="status-item">
|
| 581 |
<span class="status-label">使用比例</span>
|
| 582 |
<div style="width: 100%; text-align: right;">
|
| 583 |
+
<span class="status-value compute-points {% if user_points.percentage > 80 %}danger{% elif user_points.percentage > 50 %}warning{% endif %}">
|
| 584 |
+
{{ user_points.percentage }}%
|
| 585 |
</span>
|
| 586 |
<div class="progress-container">
|
| 587 |
+
<div class="progress-bar {% if user_points.percentage > 80 %}danger{% elif user_points.percentage > 50 %}warning{% endif %}" style="width: {{ user_points.percentage }}%"></div>
|
| 588 |
</div>
|
| 589 |
</div>
|
| 590 |
</div>
|
| 591 |
+
{% if user_points.last_update %}
|
| 592 |
<div class="status-item">
|
| 593 |
<span class="status-label">最后更新时间</span>
|
| 594 |
+
<span class="status-value">{{ user_points.last_update.strftime('%Y-%m-%d %H:%M:%S') }}</span>
|
| 595 |
</div>
|
| 596 |
{% endif %}
|
| 597 |
+
{% endif %} {# End if user_points.error #}
|
| 598 |
+
</div>
|
| 599 |
+
{% endfor %}
|
| 600 |
+
{% else %}
|
| 601 |
+
<div class="card">
|
| 602 |
+
<div class="card-header">
|
| 603 |
+
<h2 class="card-title">
|
| 604 |
+
<span class="card-icon">💰</span>
|
| 605 |
+
计算点信息
|
| 606 |
+
</h2>
|
| 607 |
+
</div>
|
| 608 |
+
<div class="status-item">
|
| 609 |
+
<span class="status-label">状态</span>
|
| 610 |
+
<span class="status-value warning">暂无计算点数据或未配置用户</span>
|
| 611 |
+
</div>
|
| 612 |
</div>
|
| 613 |
+
{% endif %} {# End if compute_points #}
|
| 614 |
|
| 615 |
<div class="card">
|
| 616 |
<div class="card-header">
|