新增后台管理系统

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

技术:
- Flask + Tailwind CSS
- 解析TypeScript数据文件
- 端口: 19006
This commit is contained in:
2026-04-08 14:13:06 +08:00
parent 0561c6da6f
commit f249f28eb7
6 changed files with 1051 additions and 0 deletions
+94
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
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
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
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>