Spaces:
Paused
Paused
Upload 4 files
Browse files- app.py +90 -54
- templates/dashboard.html +45 -1
app.py
CHANGED
|
@@ -70,6 +70,8 @@ compute_points_log = {
|
|
| 70 |
"log": [] # 日志数据
|
| 71 |
}
|
| 72 |
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# 记录启动时间
|
| 75 |
START_TIME = datetime.now()
|
|
@@ -821,64 +823,97 @@ def update_model_stats(model, prompt_tokens, completion_tokens):
|
|
| 821 |
|
| 822 |
# 获取计算点信息
|
| 823 |
def get_compute_points():
|
| 824 |
-
global compute_points, USER_DATA
|
| 825 |
|
| 826 |
if USER_NUM == 0:
|
| 827 |
return
|
| 828 |
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 876 |
else:
|
| 877 |
-
print(f"
|
| 878 |
-
|
| 879 |
-
print(f"
|
| 880 |
-
|
| 881 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 882 |
|
| 883 |
# 获取计算点使用日志
|
| 884 |
def get_compute_points_log(session, cookies, session_token):
|
|
@@ -975,7 +1010,8 @@ def dashboard():
|
|
| 975 |
total_tokens=total_tokens,
|
| 976 |
compute_points=compute_points,
|
| 977 |
compute_points_log=compute_points_log,
|
| 978 |
-
space_url=SPACE_URL # 传递空间URL
|
|
|
|
| 979 |
)
|
| 980 |
|
| 981 |
|
|
|
|
| 70 |
"log": [] # 日志数据
|
| 71 |
}
|
| 72 |
|
| 73 |
+
# 多用户计算点信息
|
| 74 |
+
users_compute_points = []
|
| 75 |
|
| 76 |
# 记录启动时间
|
| 77 |
START_TIME = datetime.now()
|
|
|
|
| 823 |
|
| 824 |
# 获取计算点信息
|
| 825 |
def get_compute_points():
|
| 826 |
+
global compute_points, USER_DATA, users_compute_points
|
| 827 |
|
| 828 |
if USER_NUM == 0:
|
| 829 |
return
|
| 830 |
|
| 831 |
+
# 清空用户计算点列表
|
| 832 |
+
users_compute_points = []
|
| 833 |
+
|
| 834 |
+
# 累计总计算点
|
| 835 |
+
total_left = 0
|
| 836 |
+
total_points = 0
|
| 837 |
+
|
| 838 |
+
# 获取每个用户的计算点信息
|
| 839 |
+
for i, user_data in enumerate(USER_DATA):
|
| 840 |
+
try:
|
| 841 |
+
session, cookies, session_token, _, _ = user_data
|
| 842 |
+
|
| 843 |
+
# 检查token是否有效
|
| 844 |
+
if is_token_expired(session_token):
|
| 845 |
+
session_token = refresh_token(session, cookies)
|
| 846 |
+
if not session_token:
|
| 847 |
+
print(f"用户{i+1}刷新token失败,无法获取计算点信息")
|
| 848 |
+
continue
|
| 849 |
+
USER_DATA[i] = (session, cookies, session_token, user_data[3], user_data[4])
|
| 850 |
+
|
| 851 |
+
headers = {
|
| 852 |
+
"accept": "application/json, text/plain, */*",
|
| 853 |
+
"accept-language": "zh-CN,zh;q=0.9",
|
| 854 |
+
"baggage": f"sentry-environment=production,sentry-release=93da8385541a6ce339b1f41b0c94428c70657e22,sentry-public_key=3476ea6df1585dd10e92cdae3a66ff49,sentry-trace_id={TRACE_ID}",
|
| 855 |
+
"reai-ui": "1",
|
| 856 |
+
"sec-ch-ua": "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"",
|
| 857 |
+
"sec-ch-ua-mobile": "?0",
|
| 858 |
+
"sec-ch-ua-platform": "\"Windows\"",
|
| 859 |
+
"sec-fetch-dest": "empty",
|
| 860 |
+
"sec-fetch-mode": "cors",
|
| 861 |
+
"sec-fetch-site": "same-origin",
|
| 862 |
+
"sentry-trace": SENTRY_TRACE,
|
| 863 |
+
"session-token": session_token,
|
| 864 |
+
"x-abacus-org-host": "apps",
|
| 865 |
+
"cookie": cookies
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
response = session.get(
|
| 869 |
+
COMPUTE_POINTS_URL,
|
| 870 |
+
headers=headers
|
| 871 |
+
)
|
| 872 |
+
|
| 873 |
+
if response.status_code == 200:
|
| 874 |
+
result = response.json()
|
| 875 |
+
if result.get("success") and "result" in result:
|
| 876 |
+
data = result["result"]
|
| 877 |
+
left = data.get("computePointsLeft", 0)
|
| 878 |
+
total = data.get("totalComputePoints", 0)
|
| 879 |
+
used = total - left
|
| 880 |
+
percentage = round((used / total) * 100, 2) if total > 0 else 0
|
| 881 |
+
|
| 882 |
+
# 添加到用户列表
|
| 883 |
+
user_points = {
|
| 884 |
+
"user_id": i + 1, # 用户ID从1开始
|
| 885 |
+
"left": left,
|
| 886 |
+
"total": total,
|
| 887 |
+
"used": used,
|
| 888 |
+
"percentage": percentage,
|
| 889 |
+
"last_update": datetime.now()
|
| 890 |
+
}
|
| 891 |
+
users_compute_points.append(user_points)
|
| 892 |
+
|
| 893 |
+
# 累计总数
|
| 894 |
+
total_left += left
|
| 895 |
+
total_points += total
|
| 896 |
+
|
| 897 |
+
print(f"用户{i+1}计算点信息更新成功: 剩余 {left}, 总计 {total}")
|
| 898 |
+
|
| 899 |
+
# 对于第一个用户,获取计算点使用日志
|
| 900 |
+
if i == 0:
|
| 901 |
+
get_compute_points_log(session, cookies, session_token)
|
| 902 |
+
else:
|
| 903 |
+
print(f"获取用户{i+1}计算点信息失败: {result.get('error', '未知错误')}")
|
| 904 |
else:
|
| 905 |
+
print(f"获取用户{i+1}计算点信息失败,状态码: {response.status_code}")
|
| 906 |
+
except Exception as e:
|
| 907 |
+
print(f"获取用户{i+1}计算点信息异常: {e}")
|
| 908 |
+
|
| 909 |
+
# 更新全局计算点信息(所有用户总和)
|
| 910 |
+
if users_compute_points:
|
| 911 |
+
compute_points["left"] = total_left
|
| 912 |
+
compute_points["total"] = total_points
|
| 913 |
+
compute_points["used"] = total_points - total_left
|
| 914 |
+
compute_points["percentage"] = round((compute_points["used"] / compute_points["total"]) * 100, 2) if compute_points["total"] > 0 else 0
|
| 915 |
+
compute_points["last_update"] = datetime.now()
|
| 916 |
+
print(f"所有用户计算点总计: 剩余 {total_left}, 总计 {total_points}")
|
| 917 |
|
| 918 |
# 获取计算点使用日志
|
| 919 |
def get_compute_points_log(session, cookies, session_token):
|
|
|
|
| 1010 |
total_tokens=total_tokens,
|
| 1011 |
compute_points=compute_points,
|
| 1012 |
compute_points_log=compute_points_log,
|
| 1013 |
+
space_url=SPACE_URL, # 传递空间URL
|
| 1014 |
+
users_compute_points=users_compute_points # 传递用户计算点信息
|
| 1015 |
)
|
| 1016 |
|
| 1017 |
|
templates/dashboard.html
CHANGED
|
@@ -554,7 +554,7 @@
|
|
| 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">
|
|
@@ -635,6 +635,50 @@
|
|
| 635 |
</div>
|
| 636 |
</div>
|
| 637 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
<div class="card">
|
| 639 |
<div class="card-header">
|
| 640 |
<h2 class="card-title">
|
|
|
|
| 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">
|
|
|
|
| 635 |
</div>
|
| 636 |
</div>
|
| 637 |
|
| 638 |
+
{% if users_compute_points|length > 0 %}
|
| 639 |
+
<div class="card">
|
| 640 |
+
<div class="card-header">
|
| 641 |
+
<h2 class="card-title">
|
| 642 |
+
<span class="card-icon">👥</span>
|
| 643 |
+
用户计算点详情
|
| 644 |
+
</h2>
|
| 645 |
+
</div>
|
| 646 |
+
<div class="table-container">
|
| 647 |
+
<table class="data-table">
|
| 648 |
+
<thead>
|
| 649 |
+
<tr>
|
| 650 |
+
<th>用户</th>
|
| 651 |
+
<th>总计算点</th>
|
| 652 |
+
<th>已使用</th>
|
| 653 |
+
<th>剩余</th>
|
| 654 |
+
<th>使用比例</th>
|
| 655 |
+
</tr>
|
| 656 |
+
</thead>
|
| 657 |
+
<tbody>
|
| 658 |
+
{% for user in users_compute_points %}
|
| 659 |
+
<tr>
|
| 660 |
+
<td>用户 {{ user.user_id }}</td>
|
| 661 |
+
<td class="compute-points">{{ user.total|int }}</td>
|
| 662 |
+
<td class="compute-points">{{ user.used|int }}</td>
|
| 663 |
+
<td class="compute-points">{{ user.left|int }}</td>
|
| 664 |
+
<td>
|
| 665 |
+
<div style="width: 100%; position: relative;">
|
| 666 |
+
<span class="status-value compute-points {% if user.percentage > 80 %}danger{% elif user.percentage > 50 %}warning{% endif %}">
|
| 667 |
+
{{ user.percentage }}%
|
| 668 |
+
</span>
|
| 669 |
+
<div class="progress-container">
|
| 670 |
+
<div class="progress-bar {% if user.percentage > 80 %}danger{% elif user.percentage > 50 %}warning{% endif %}" style="width: {{ user.percentage }}%"></div>
|
| 671 |
+
</div>
|
| 672 |
+
</div>
|
| 673 |
+
</td>
|
| 674 |
+
</tr>
|
| 675 |
+
{% endfor %}
|
| 676 |
+
</tbody>
|
| 677 |
+
</table>
|
| 678 |
+
</div>
|
| 679 |
+
</div>
|
| 680 |
+
{% endif %}
|
| 681 |
+
|
| 682 |
<div class="card">
|
| 683 |
<div class="card-header">
|
| 684 |
<h2 class="card-title">
|