1 Commits

Author SHA1 Message Date
f249f28eb7 新增后台管理系统
功能模块:
- 仪表盘: 模型/GPU/CPU统计、开源/闭源分布、快速操作
- 模型管理: 查看模型列表、筛选搜索、添加新模型
- GPU管理: 查看GPU列表、厂商筛选、添加新GPU
- CPU管理: 查看CPU列表
- 数据导出: 导出模型/GPU数据为JSON

技术:
- Flask + Tailwind CSS
- 解析TypeScript数据文件
- 端口: 19006
2026-04-08 14:13:06 +08:00
6 changed files with 1051 additions and 0 deletions

254
admin/app.py Normal file
View File

@@ -0,0 +1,254 @@
"""
参数百科网站 - 后台管理系统
"""
from flask import Flask, render_template, jsonify, request
from flask_cors import CORS
import json
from pathlib import Path
from datetime import datetime
app = Flask(__name__)
CORS(app)
# 数据目录 - 读取 Next.js 项目的数据文件
DATA_DIR = Path(__file__).parent.parent / 'src' / 'data'
def load_models():
"""加载模型数据"""
init_file = DATA_DIR / 'initial.ts'
if init_file.exists():
# 从 TypeScript 文件解析数据
content = init_file.read_text(encoding='utf-8')
return parse_ts_data(content, 'models')
return []
def load_gpus():
"""加载GPU数据"""
init_file = DATA_DIR / 'initial.ts'
if init_file.exists():
content = init_file.read_text(encoding='utf-8')
return parse_ts_data(content, 'gpus')
return []
def load_cpus():
"""加载CPU数据"""
init_file = DATA_DIR / 'initial.ts'
if init_file.exists():
content = init_file.read_text(encoding='utf-8')
return parse_ts_data(content, 'cpus')
return []
def parse_ts_data(content, data_type):
"""简单解析 TypeScript 数据"""
import re
# 找到数据定义的开始位置
patterns = {
'models': r'export const models: Model\[\]\s*=\s*\[([\s\S]*?)\n\]',
'gpus': r'export const gpus: Gpu\[\]\s*=\s*\[([\s\S]*?)\n\]',
'cpus': r'export const cpus: Cpu\[\]\s*=\s*\[([\s\S]*?)\n\]',
}
pattern = patterns.get(data_type)
if not pattern:
return []
match = re.search(pattern, content)
if not match:
return []
data_str = match.group(1)
# 简单的对象解析
items = []
current_item = {}
current_key = None
current_value = []
in_string = False
in_object = 0
lines = data_str.split('\n')
for line in lines:
line = line.strip()
if line == '{':
current_item = {}
in_object += 1
elif line == '},' or line == '}':
if current_item:
items.append(current_item)
current_item = {}
in_object = max(0, in_object - 1)
elif ':' in line and in_object > 0:
parts = line.split(':', 1)
key = parts[0].strip()
value = parts[1].strip().rstrip(',')
if value.startswith('"') or value.startswith("'"):
value = value.strip('"\'')
elif value == 'null':
value = None
elif value == 'true':
value = True
elif value == 'false':
value = False
elif value.startswith('['):
# 数组类型
value = value.strip('[]').replace('"', '').split(',') if value != '[]' else []
value = [v.strip() for v in value if v.strip()]
else:
try:
value = int(value) if '.' not in value else float(value)
except:
pass
current_item[key] = value
return items
def save_models(models):
"""保存模型数据"""
# 这里需要更新 TypeScript 文件
# 为简化,我们使用 JSON 文件存储变更
data_dir = Path(__file__).parent.parent / 'data'
data_dir.mkdir(exist_ok=True)
(data_dir / 'models.json').write_text(json.dumps(models, ensure_ascii=False, indent=2), encoding='utf-8')
def save_gpus(gpus):
"""保存GPU数据"""
data_dir = Path(__file__).parent.parent / 'data'
data_dir.mkdir(exist_ok=True)
(data_dir / 'gpus.json').write_text(json.dumps(gpus, ensure_ascii=False, indent=2), encoding='utf-8')
# ============ 页面路由 ============
@app.route('/')
def index():
return render_template('index.html')
@app.route('/models')
def models_page():
return render_template('models.html')
@app.route('/gpus')
def gpus_page():
return render_template('gpus.html')
@app.route('/cpus')
def cpus_page():
return render_template('cpus.html')
# ============ API路由 ============
@app.route('/api/stats')
def api_stats():
models = load_models()
gpus = load_gpus()
cpus = load_cpus()
# 统计
open_source = sum(1 for m in models if m.get('isOpenSource'))
nvidia_gpus = sum(1 for g in gpus if g.get('manufacturer') == 'NVIDIA')
amd_gpus = sum(1 for g in gpus if g.get('manufacturer') == 'AMD')
return jsonify({
'models_count': len(models),
'gpus_count': len(gpus),
'cpus_count': len(cpus),
'open_source_models': open_source,
'closed_source_models': len(models) - open_source,
'nvidia_gpus': nvidia_gpus,
'amd_gpus': amd_gpus,
})
@app.route('/api/models')
def api_models():
models = load_models()
return jsonify(models)
@app.route('/api/models', methods=['POST'])
def api_add_model():
data = request.json
models = load_models()
new_model = {
'name': data.get('name', ''),
'slug': data.get('slug', data.get('name', '').lower().replace(' ', '-')),
'organization': data.get('organization', ''),
'parametersCount': data.get('parametersCount'),
'architecture': data.get('architecture'),
'contextLength': data.get('contextLength'),
'isOpenSource': data.get('isOpenSource', False),
'license': data.get('license'),
'benchmarkMmlu': data.get('benchmarkMmlu'),
'benchmarkHumaneval': data.get('benchmarkHumaneval'),
'minVramFp16': data.get('minVramFp16'),
'minVramInt8': data.get('minVramInt8'),
'minVramInt4': data.get('minVramInt4'),
}
models.append(new_model)
save_models(models)
return jsonify({'success': True, 'model': new_model})
@app.route('/api/gpus')
def api_gpus():
gpus = load_gpus()
return jsonify(gpus)
@app.route('/api/gpus', methods=['POST'])
def api_add_gpu():
data = request.json
gpus = load_gpus()
new_gpu = {
'name': data.get('name', ''),
'slug': data.get('slug', data.get('name', '').lower().replace(' ', '-')),
'manufacturer': data.get('manufacturer', 'NVIDIA'),
'architecture': data.get('architecture'),
'cudaCores': data.get('cudaCores'),
'tensorCores': data.get('tensorCores'),
'memoryGb': data.get('memoryGb'),
'memoryType': data.get('memoryType'),
'memoryBandwidthGbps': data.get('memoryBandwidthGbps'),
'fp32Tflops': data.get('fp32Tflops'),
'fp16Tflops': data.get('fp16Tflops'),
'tdpWatts': data.get('tdpWatts'),
'priceUsd': data.get('priceUsd'),
'recommendedFor': data.get('recommendedFor', []),
}
gpus.append(new_gpu)
save_gpus(gpus)
return jsonify({'success': True, 'gpu': new_gpu})
@app.route('/api/cpus')
def api_cpus():
cpus = load_cpus()
return jsonify(cpus)
@app.route('/api/export/models')
def api_export_models():
"""导出模型数据为 JSON"""
models = load_models()
return jsonify(models)
@app.route('/api/export/gpus')
def api_export_gpus():
"""导出GPU数据为 JSON"""
gpus = load_gpus()
return jsonify(gpus)
if __name__ == '__main__':
print("=" * 50)
print("参数百科网站 - 后台管理系统")
print("=" * 50)
print(f"访问地址: http://localhost:19006")
print(f"前台地址: http://localhost:3000")
print("=" * 50)
app.run(host='0.0.0.0', port=19006, debug=True)

2
admin/requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
flask>=2.3.0
flask-cors>=4.0.0

94
admin/templates/cpus.html Normal file
View File

@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPU管理 - 参数百科后台</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-database-2-line text-2xl text-blue-400"></i>
参数百科后台
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/models" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>模型管理</span>
</a>
<a href="/gpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-3-line"></i><span>GPU管理</span>
</a>
<a href="/cpus" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-cpu-line"></i><span>CPU管理</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<h1 class="text-2xl font-bold text-gray-800 mb-6">CPU管理</h1>
<!-- CPU列表 -->
<div class="bg-white rounded-xl border border-gray-100 overflow-x-auto">
<table class="w-full min-w-[1000px]">
<thead class="bg-gray-50 border-b border-gray-100">
<tr>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">CPU名称</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">厂商</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">架构</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">核心/线程</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">频率</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">缓存</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">功耗</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">价格</th>
</tr>
</thead>
<tbody id="cpuTable">
<tr><td colspan="8" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
</tbody>
</table>
</div>
</main>
</div>
<script>
async function loadCpus() {
const res = await fetch('/api/cpus');
const cpus = await res.json();
const tbody = document.getElementById('cpuTable');
if (cpus.length === 0) {
tbody.innerHTML = '<tr><td colspan="8" class="px-6 py-8 text-center text-gray-500">暂无CPU数据</td></tr>';
return;
}
tbody.innerHTML = cpus.map(c => `
<tr class="border-b border-gray-50 hover:bg-gray-50">
<td class="px-4 py-3 font-medium text-gray-800">${c.name}</td>
<td class="px-4 py-3">
<span class="px-2 py-1 rounded text-xs ${c.manufacturer === 'AMD' ? 'bg-red-100 text-red-600' : 'bg-blue-100 text-blue-600'}">
${c.manufacturer}
</span>
</td>
<td class="px-4 py-3 text-gray-600">${c.architecture || '-'}</td>
<td class="px-4 py-3">${c.cores}核 / ${c.threads}线程</td>
<td class="px-4 py-3">${c.baseClockGhz || '-'} / ${c.boostClockGhz || '-'} GHz</td>
<td class="px-4 py-3">${c.l3CacheMb ? c.l3CacheMb + 'MB' : '-'}</td>
<td class="px-4 py-3">${c.tdpWatts ? c.tdpWatts + 'W' : '-'}</td>
<td class="px-4 py-3 text-blue-600">${c.priceUsd ? '$' + c.priceUsd.toLocaleString() : '-'}</td>
</tr>
`).join('');
}
loadCpus();
</script>
</body>
</html>

252
admin/templates/gpus.html Normal file
View File

@@ -0,0 +1,252 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPU管理 - 参数百科后台</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-database-2-line text-2xl text-blue-400"></i>
参数百科后台
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/models" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>模型管理</span>
</a>
<a href="/gpus" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-dashboard-3-line"></i><span>GPU管理</span>
</a>
<a href="/cpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>CPU管理</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold text-gray-800">GPU管理</h1>
<button onclick="showAddModal()" class="px-4 py-2 bg-green-500 text-white rounded-lg flex items-center gap-2 hover:bg-green-600">
<i class="ri-add-line"></i> 添加GPU
</button>
</div>
<!-- 筛选 -->
<div class="bg-white rounded-lg p-4 mb-6 border border-gray-100">
<div class="flex gap-4 items-center">
<input type="text" id="searchInput" placeholder="搜索GPU名称..."
class="flex-1 px-4 py-2 border border-gray-200 rounded-lg"
onkeyup="filterGpus()">
<select id="filterManufacturer" onchange="filterGpus()" class="px-4 py-2 border border-gray-200 rounded-lg">
<option value="all">全部厂商</option>
<option value="NVIDIA">NVIDIA</option>
<option value="AMD">AMD</option>
</select>
</div>
</div>
<!-- GPU列表 -->
<div class="bg-white rounded-xl border border-gray-100 overflow-x-auto">
<table class="w-full min-w-[1000px]">
<thead class="bg-gray-50 border-b border-gray-100">
<tr>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">GPU名称</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">厂商</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">架构</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">显存</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">CUDA核心</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">FP16算力</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">功耗</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">价格</th>
<th class="px-4 py-3 text-left text-sm font-medium text-gray-500">操作</th>
</tr>
</thead>
<tbody id="gpuTable">
<tr><td colspan="9" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
</tbody>
</table>
</div>
</main>
</div>
<!-- 添加GPU弹窗 -->
<div id="addModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50 p-4">
<div class="bg-white rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-bold text-lg">添加新GPU</h3>
<button onclick="closeAddModal()" class="text-gray-400"><i class="ri-close-line text-2xl"></i></button>
</div>
<div class="p-4 overflow-auto flex-1">
<form id="addForm" class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm text-gray-600 mb-1">GPU名称 *</label>
<input type="text" name="name" required class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">厂商</label>
<select name="manufacturer" class="w-full px-3 py-2 border rounded-lg">
<option value="NVIDIA">NVIDIA</option>
<option value="AMD">AMD</option>
</select>
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">架构</label>
<input type="text" name="architecture" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">显存(GB)</label>
<input type="number" name="memoryGb" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">显存类型</label>
<input type="text" name="memoryType" placeholder="如 HBM3, GDDR6X" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">CUDA核心</label>
<input type="number" name="cudaCores" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">Tensor核心</label>
<input type="number" name="tensorCores" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">显存带宽(GB/s)</label>
<input type="number" name="memoryBandwidthGbps" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">FP32算力(TFLOPS)</label>
<input type="number" step="0.1" name="fp32Tflops" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">FP16算力(TFLOPS)</label>
<input type="number" step="0.1" name="fp16Tflops" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">功耗(W)</label>
<input type="number" name="tdpWatts" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">价格(USD)</label>
<input type="number" name="priceUsd" class="w-full px-3 py-2 border rounded-lg">
</div>
</form>
</div>
<div class="p-4 border-t flex justify-end gap-3">
<button onclick="closeAddModal()" class="px-4 py-2 border rounded-lg">取消</button>
<button onclick="submitGpu()" class="px-4 py-2 bg-green-500 text-white rounded-lg">添加</button>
</div>
</div>
</div>
<script>
let allGpus = [];
async function loadGpus() {
const res = await fetch('/api/gpus');
allGpus = await res.json();
renderGpus(allGpus);
}
function renderGpus(gpus) {
const tbody = document.getElementById('gpuTable');
if (gpus.length === 0) {
tbody.innerHTML = '<tr><td colspan="9" class="px-6 py-8 text-center text-gray-500">暂无GPU数据</td></tr>';
return;
}
tbody.innerHTML = gpus.map(g => `
<tr class="border-b border-gray-50 hover:bg-gray-50">
<td class="px-4 py-3 font-medium text-gray-800">${g.name}</td>
<td class="px-4 py-3">
<span class="px-2 py-1 rounded text-xs ${g.manufacturer === 'NVIDIA' ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'}">
${g.manufacturer}
</span>
</td>
<td class="px-4 py-3 text-gray-600">${g.architecture || '-'}</td>
<td class="px-4 py-3">${g.memoryGb ? g.memoryGb + 'GB ' + (g.memoryType || '') : '-'}</td>
<td class="px-4 py-3">${g.cudaCores ? g.cudaCores.toLocaleString() : '-'}</td>
<td class="px-4 py-3 text-orange-600">${g.fp16Tflops ? g.fp16Tflops.toLocaleString() + ' TF' : '-'}</td>
<td class="px-4 py-3">${g.tdpWatts ? g.tdpWatts + 'W' : '-'}</td>
<td class="px-4 py-3 text-blue-600">${g.priceUsd ? '$' + g.priceUsd.toLocaleString() : '-'}</td>
<td class="px-4 py-3">
<button class="text-blue-500 hover:text-blue-700 mr-2"><i class="ri-edit-line"></i></button>
<button class="text-red-500 hover:text-red-700"><i class="ri-delete-bin-line"></i></button>
</td>
</tr>
`).join('');
}
function filterGpus() {
const search = document.getElementById('searchInput').value.toLowerCase();
const manufacturer = document.getElementById('filterManufacturer').value;
let filtered = allGpus;
if (search) {
filtered = filtered.filter(g => g.name.toLowerCase().includes(search));
}
if (manufacturer !== 'all') {
filtered = filtered.filter(g => g.manufacturer === manufacturer);
}
renderGpus(filtered);
}
function showAddModal() {
document.getElementById('addModal').classList.remove('hidden');
document.getElementById('addModal').classList.add('flex');
}
function closeAddModal() {
document.getElementById('addModal').classList.add('hidden');
document.getElementById('addModal').classList.remove('flex');
}
async function submitGpu() {
const form = document.getElementById('addForm');
const formData = new FormData(form);
const data = {};
formData.forEach((value, key) => {
if (value) {
if (!isNaN(value) && value !== '') {
data[key] = parseFloat(value);
} else {
data[key] = value;
}
}
});
try {
const res = await fetch('/api/gpus', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const result = await res.json();
if (result.success) {
closeAddModal();
loadGpus();
alert('GPU添加成功');
}
} catch (err) {
alert('添加失败,请重试');
}
}
loadGpus();
</script>
</body>
</html>

202
admin/templates/index.html Normal file
View File

@@ -0,0 +1,202 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>参数百科 - 后台管理</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
<style>
.gradient-bg { background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%); }
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<!-- 侧边栏 -->
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-database-2-line text-2xl text-blue-400"></i>
参数百科后台
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/models" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>模型管理</span>
</a>
<a href="/gpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-3-line"></i><span>GPU管理</span>
</a>
<a href="/cpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>CPU管理</span>
</a>
</nav>
<div class="absolute bottom-0 left-0 right-0 p-4 border-t border-slate-700">
<a href="http://localhost:3000" target="_blank" class="text-slate-400 hover:text-white text-sm flex items-center gap-2">
<i class="ri-external-link-line"></i> 访问前台
</a>
</div>
</aside>
<!-- 主内容 -->
<main class="ml-64 flex-1 p-8">
<!-- 统计卡片 -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">模型总数</p>
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-models">-</p>
</div>
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<i class="ri-cpu-line text-2xl text-blue-600"></i>
</div>
</div>
<div class="mt-2 flex gap-4 text-xs">
<span class="text-green-600">开源: <span id="stat-open">0</span></span>
<span class="text-gray-500">闭源: <span id="stat-closed">0</span></span>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">GPU总数</p>
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-gpus">-</p>
</div>
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
<i class="ri-dashboard-3-line text-2xl text-green-600"></i>
</div>
</div>
<div class="mt-2 flex gap-4 text-xs">
<span class="text-green-600">NVIDIA: <span id="stat-nvidia">0</span></span>
<span class="text-red-500">AMD: <span id="stat-amd">0</span></span>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">CPU总数</p>
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-cpus">-</p>
</div>
<div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center">
<i class="ri-cpu-line text-2xl text-purple-600"></i>
</div>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">数据完整性</p>
<p class="text-2xl font-bold text-green-600 mt-2">良好</p>
</div>
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
<i class="ri-check-double-line text-2xl text-green-600"></i>
</div>
</div>
</div>
</div>
<!-- 快速操作 -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="ri-lightbulb-line text-yellow-500"></i>
快速操作
</h2>
<div class="space-y-3">
<a href="/models" class="flex items-center gap-3 p-3 bg-blue-50 rounded-lg hover:bg-blue-100">
<i class="ri-add-circle-line text-blue-600"></i>
<span class="text-gray-700">添加新模型</span>
</a>
<a href="/gpus" class="flex items-center gap-3 p-3 bg-green-50 rounded-lg hover:bg-green-100">
<i class="ri-add-circle-line text-green-600"></i>
<span class="text-gray-700">添加新GPU</span>
</a>
<a href="/cpus" class="flex items-center gap-3 p-3 bg-purple-50 rounded-lg hover:bg-purple-100">
<i class="ri-add-circle-line text-purple-600"></i>
<span class="text-gray-700">添加新CPU</span>
</a>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="ri-download-line text-blue-500"></i>
数据导出
</h2>
<div class="space-y-3">
<a href="/api/export/models" class="flex items-center gap-3 p-3 bg-gray-50 rounded-lg hover:bg-gray-100">
<i class="ri-file-text-line text-gray-600"></i>
<span class="text-gray-700">导出模型数据 (JSON)</span>
</a>
<a href="/api/export/gpus" class="flex items-center gap-3 p-3 bg-gray-50 rounded-lg hover:bg-gray-100">
<i class="ri-file-text-line text-gray-600"></i>
<span class="text-gray-700">导出GPU数据 (JSON)</span>
</a>
</div>
</div>
</div>
<!-- 最近添加 -->
<div class="mt-6 bg-white rounded-xl shadow-sm border border-gray-100 p-6">
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="ri-time-line text-purple-500"></i>
最新模型
</h2>
<div id="recentModels" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<p class="text-gray-500">加载中...</p>
</div>
</div>
</main>
</div>
<script>
async function loadStats() {
const res = await fetch('/api/stats');
const data = await res.json();
document.getElementById('stat-models').textContent = data.models_count;
document.getElementById('stat-gpus').textContent = data.gpus_count;
document.getElementById('stat-cpus').textContent = data.cpus_count;
document.getElementById('stat-open').textContent = data.open_source_models;
document.getElementById('stat-closed').textContent = data.closed_source_models;
document.getElementById('stat-nvidia').textContent = data.nvidia_gpus;
document.getElementById('stat-amd').textContent = data.amd_gpus;
}
async function loadRecentModels() {
const res = await fetch('/api/models');
const models = await res.json();
const container = document.getElementById('recentModels');
if (models.length === 0) {
container.innerHTML = '<p class="text-gray-500">暂无模型数据</p>';
return;
}
container.innerHTML = models.slice(0, 6).map(m => `
<div class="p-4 bg-gray-50 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<span class="font-medium text-gray-800">${m.name}</span>
${m.isOpenSource ? '<span class="text-xs px-2 py-0.5 bg-green-100 text-green-600 rounded">开源</span>' : ''}
</div>
<p class="text-sm text-gray-500">${m.organization || '未知'}</p>
<p class="text-xs text-gray-400 mt-1">
${m.parametersCount ? m.parametersCount + 'B 参数' : '参数未知'}
${m.contextLength ? ' · ' + (m.contextLength >= 1000 ? m.contextLength/1000 + 'K' : m.contextLength) + ' 上下文' : ''}
</p>
</div>
`).join('');
}
loadStats();
loadRecentModels();
</script>
</body>
</html>

247
admin/templates/models.html Normal file
View File

@@ -0,0 +1,247 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模型管理 - 参数百科后台</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-database-2-line text-2xl text-blue-400"></i>
参数百科后台
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/models" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-cpu-line"></i><span>模型管理</span>
</a>
<a href="/gpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-3-line"></i><span>GPU管理</span>
</a>
<a href="/cpus" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-cpu-line"></i><span>CPU管理</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold text-gray-800">模型管理</h1>
<button onclick="showAddModal()" class="px-4 py-2 gradient-bg text-white rounded-lg flex items-center gap-2">
<i class="ri-add-line"></i> 添加模型
</button>
</div>
<!-- 筛选 -->
<div class="bg-white rounded-lg p-4 mb-6 border border-gray-100">
<div class="flex gap-4 items-center">
<input type="text" id="searchInput" placeholder="搜索模型名称..."
class="flex-1 px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-blue-500"
onkeyup="filterModels()">
<select id="filterSource" onchange="filterModels()" class="px-4 py-2 border border-gray-200 rounded-lg">
<option value="all">全部</option>
<option value="open">开源</option>
<option value="closed">闭源</option>
</select>
</div>
</div>
<!-- 模型列表 -->
<div class="bg-white rounded-xl border border-gray-100 overflow-hidden">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-100">
<tr>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">模型名称</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">组织</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">参数量</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">上下文</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">类型</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">MMLU</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">操作</th>
</tr>
</thead>
<tbody id="modelTable">
<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
</tbody>
</table>
</div>
</main>
</div>
<!-- 添加模型弹窗 -->
<div id="addModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50 p-4">
<div class="bg-white rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-bold text-lg">添加新模型</h3>
<button onclick="closeAddModal()" class="text-gray-400"><i class="ri-close-line text-2xl"></i></button>
</div>
<div class="p-4 overflow-auto flex-1">
<form id="addForm" class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm text-gray-600 mb-1">模型名称 *</label>
<input type="text" name="name" required class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">组织</label>
<input type="text" name="organization" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">参数量 (B)</label>
<input type="number" name="parametersCount" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">上下文长度</label>
<input type="number" name="contextLength" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">架构</label>
<input type="text" name="architecture" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">开源</label>
<select name="isOpenSource" class="w-full px-3 py-2 border rounded-lg">
<option value="false"></option>
<option value="true"></option>
</select>
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">许可证</label>
<input type="text" name="license" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">MMLU分数</label>
<input type="number" step="0.1" name="benchmarkMmlu" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">HumanEval分数</label>
<input type="number" step="0.1" name="benchmarkHumaneval" class="w-full px-3 py-2 border rounded-lg">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">FP16显存(GB)</label>
<input type="number" name="minVramFp16" class="w-full px-3 py-2 border rounded-lg">
</div>
</form>
</div>
<div class="p-4 border-t flex justify-end gap-3">
<button onclick="closeAddModal()" class="px-4 py-2 border rounded-lg">取消</button>
<button onclick="submitModel()" class="px-4 py-2 gradient-bg text-white rounded-lg">添加</button>
</div>
</div>
</div>
<script>
let allModels = [];
async function loadModels() {
const res = await fetch('/api/models');
allModels = await res.json();
renderModels(allModels);
}
function renderModels(models) {
const tbody = document.getElementById('modelTable');
if (models.length === 0) {
tbody.innerHTML = '<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">暂无模型数据</td></tr>';
return;
}
tbody.innerHTML = models.map(m => `
<tr class="border-b border-gray-50 hover:bg-gray-50">
<td class="px-6 py-4 font-medium text-gray-800">${m.name}</td>
<td class="px-6 py-4 text-gray-600">${m.organization || '-'}</td>
<td class="px-6 py-4">${m.parametersCount ? m.parametersCount + 'B' : '-'}</td>
<td class="px-6 py-4">${m.contextLength ? (m.contextLength >= 1000 ? m.contextLength/1000 + 'K' : m.contextLength) : '-'}</td>
<td class="px-6 py-4">
${m.isOpenSource
? '<span class="px-2 py-1 bg-green-100 text-green-600 rounded text-xs">开源</span>'
: '<span class="px-2 py-1 bg-gray-100 text-gray-600 rounded text-xs">闭源</span>'}
</td>
<td class="px-6 py-4 text-blue-600">${m.benchmarkMmlu || '-'}</td>
<td class="px-6 py-4">
<button class="text-blue-500 hover:text-blue-700 mr-2"><i class="ri-edit-line"></i></button>
<button class="text-red-500 hover:text-red-700"><i class="ri-delete-bin-line"></i></button>
</td>
</tr>
`).join('');
}
function filterModels() {
const search = document.getElementById('searchInput').value.toLowerCase();
const source = document.getElementById('filterSource').value;
let filtered = allModels;
if (search) {
filtered = filtered.filter(m =>
m.name.toLowerCase().includes(search) ||
(m.organization && m.organization.toLowerCase().includes(search))
);
}
if (source === 'open') {
filtered = filtered.filter(m => m.isOpenSource);
} else if (source === 'closed') {
filtered = filtered.filter(m => !m.isOpenSource);
}
renderModels(filtered);
}
function showAddModal() {
document.getElementById('addModal').classList.remove('hidden');
document.getElementById('addModal').classList.add('flex');
}
function closeAddModal() {
document.getElementById('addModal').classList.add('hidden');
document.getElementById('addModal').classList.remove('flex');
}
async function submitModel() {
const form = document.getElementById('addForm');
const formData = new FormData(form);
const data = {};
formData.forEach((value, key) => {
if (value) {
if (key === 'isOpenSource') {
data[key] = value === 'true';
} else if (!isNaN(value) && value !== '') {
data[key] = parseFloat(value);
} else {
data[key] = value;
}
}
});
try {
const res = await fetch('/api/models', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const result = await res.json();
if (result.success) {
closeAddModal();
loadModels();
alert('模型添加成功!');
}
} catch (err) {
alert('添加失败,请重试');
}
}
loadModels();
</script>
</body>
</html>