Files
param-hub-python/templates/compare.html
hubian 7d90603b23 feat: ParamHub参数百科Python版
功能:
- 模型数据库 (12个模型)
- GPU数据库 (10个GPU)
- CPU数据库 (8个CPU)
- 显存计算器
- 对比工具
- 知识库
2026-04-09 01:59:09 +08:00

208 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>对比工具 - ParamHub</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">
<!-- 导航栏 -->
<nav class="bg-white shadow-sm sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 py-3 flex justify-between items-center">
<a href="/" class="flex items-center gap-2">
<i class="ri-dashboard-3-line text-2xl text-indigo-600"></i>
<span class="text-xl font-bold text-gray-800">ParamHub</span>
</a>
<div class="flex gap-6 text-sm">
<a href="/" class="text-gray-600 hover:text-indigo-600">首页</a>
<a href="/models" class="text-gray-600 hover:text-indigo-600">模型</a>
<a href="/gpus" class="text-gray-600 hover:text-indigo-600">GPU</a>
<a href="/cpus" class="text-gray-600 hover:text-indigo-600">CPU</a>
<a href="/tools" class="text-gray-600 hover:text-indigo-600">工具</a>
<a href="/compare" class="text-indigo-600 font-medium">对比</a>
<a href="/knowledge" class="text-gray-600 hover:text-indigo-600">知识库</a>
</div>
</div>
</nav>
<main class="max-w-7xl mx-auto px-4 py-8">
<div class="mb-6">
<h1 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
<i class="ri-git-merge-line text-purple-600"></i>
对比工具
</h1>
<p class="text-gray-500 mt-1">多维度对比模型或硬件参数</p>
</div>
<!-- 对比类型选择 -->
<div class="bg-white rounded-xl shadow-sm p-4 mb-6">
<div class="flex gap-4">
<button onclick="setCompareType('model')" id="btnModel" class="px-4 py-2 bg-indigo-600 text-white rounded-lg">
<i class="ri-robot-line mr-2"></i>模型对比
</button>
<button onclick="setCompareType('gpu')" id="btnGpu" class="px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300">
<i class="ri-cpu-line mr-2"></i>GPU对比
</button>
<button onclick="setCompareType('cpu')" id="btnCpu" class="px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300">
<i class="ri-memory-line mr-2"></i>CPU对比
</button>
</div>
</div>
<!-- 选择列表 -->
<div class="grid grid-cols-2 gap-4 mb-6">
<div class="bg-white rounded-xl shadow-sm p-4">
<label class="text-sm font-medium text-gray-600 mb-2 block">选择第一项</label>
<select id="select1" class="w-full px-4 py-2 border border-gray-200 rounded-lg" onchange="compare()">
<option value="">请选择...</option>
</select>
</div>
<div class="bg-white rounded-xl shadow-sm p-4">
<label class="text-sm font-medium text-gray-600 mb-2 block">选择第二项</label>
<select id="select2" class="w-full px-4 py-2 border border-gray-200 rounded-lg" onchange="compare()">
<option value="">请选择...</option>
</select>
</div>
</div>
<!-- 对比结果 -->
<div id="compareResult" class="bg-white rounded-xl shadow-sm p-6 hidden">
<h2 class="text-lg font-semibold text-gray-800 mb-4">对比结果</h2>
<div id="compareTable"></div>
</div>
</main>
<script>
let compareType = 'model';
let allData = [];
async function setCompareType(type) {
compareType = type;
// 更新按钮样式
document.getElementById('btnModel').className = type === 'model'
? 'px-4 py-2 bg-indigo-600 text-white rounded-lg'
: 'px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300';
document.getElementById('btnGpu').className = type === 'gpu'
? 'px-4 py-2 bg-green-600 text-white rounded-lg'
: 'px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300';
document.getElementById('btnCpu').className = type === 'cpu'
? 'px-4 py-2 bg-purple-600 text-white rounded-lg'
: 'px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300';
// 加载数据
const res = await fetch(`/api/${type}s`);
allData = await res.json();
// 填充下拉框
const select1 = document.getElementById('select1');
const select2 = document.getElementById('select2');
select1.innerHTML = '<option value="">请选择...</option>' +
allData.map(d => `<option value="${d.id}">${d.name}</option>`).join('');
select2.innerHTML = '<option value="">请选择...</option>' +
allData.map(d => `<option value="${d.id}">${d.name}</option>`).join('');
document.getElementById('compareResult').classList.add('hidden');
}
async function compare() {
const id1 = document.getElementById('select1').value;
const id2 = document.getElementById('select2').value;
if (!id1 || !id2) {
document.getElementById('compareResult').classList.add('hidden');
return;
}
const res1 = await fetch(`/api/${compareType}s/${id1}`);
const res2 = await fetch(`/api/${compareType}s/${id2}`);
const item1 = await res1.json();
const item2 = await res2.json();
let fields = [];
if (compareType === 'model') {
fields = [
{ key: 'name', label: '名称' },
{ key: 'organization', label: '厂商' },
{ key: 'parameters', label: '参数量(B)', unit: 'B' },
{ key: 'context_length', label: '上下文长度' },
{ key: 'mmlu', label: 'MMLU分数', unit: '%' },
{ key: 'humaneval', label: 'HumanEval', unit: '%' },
{ key: 'is_open_source', label: '类型', format: v => v ? '开源' : '商业' },
{ key: 'input_price', label: '输入价格', unit: '$/1K' },
{ key: 'output_price', label: '输出价格', unit: '$/1K' },
];
} else if (compareType === 'gpu') {
fields = [
{ key: 'name', label: '名称' },
{ key: 'manufacturer', label: '厂商' },
{ key: 'architecture', label: '架构' },
{ key: 'memory_gb', label: '显存', unit: 'GB' },
{ key: 'cuda_cores', label: 'CUDA核心' },
{ key: 'fp16_tflops', label: 'FP16性能', unit: 'TF' },
{ key: 'price_usd', label: '价格', unit: '$' },
];
} else {
fields = [
{ key: 'name', label: '名称' },
{ key: 'manufacturer', label: '厂商' },
{ key: 'cores', label: '核心数' },
{ key: 'threads', label: '线程数' },
{ key: 'base_clock_ghz', label: '基础频率', unit: 'GHz' },
{ key: 'boost_clock_ghz', label: '加速频率', unit: 'GHz' },
{ key: 'l3_cache_mb', label: 'L3缓存', unit: 'MB' },
{ key: 'tdp_watts', label: 'TDP', unit: 'W' },
{ key: 'price_usd', label: '价格', unit: '$' },
];
}
const html = `
<table class="w-full">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-600">参数</th>
<th class="px-4 py-2 text-center text-sm font-medium text-gray-600">${item1.name}</th>
<th class="px-4 py-2 text-center text-sm font-medium text-gray-600">${item2.name}</th>
<th class="px-4 py-2 text-center text-sm font-medium text-gray-600">差异</th>
</tr>
</thead>
<tbody class="divide-y">
${fields.map(f => {
const v1 = item1[f.key] || '-';
const v2 = item2[f.key] || '-';
const fv1 = f.format ? f.format(v1) : (v1 + (f.unit && typeof v1 === 'number' ? f.unit : ''));
const fv2 = f.format ? f.format(v2) : (v2 + (f.unit && typeof v2 === 'number' ? f.unit : ''));
let diff = '';
if (typeof v1 === 'number' && typeof v2 === 'number') {
const d = v2 - v1;
diff = d > 0 ? `<span class="text-green-600">+${d}${f.unit || ''}</span>` :
d < 0 ? `<span class="text-red-600">${d}${f.unit || ''}</span>` : '-';
}
return `
<tr>
<td class="px-4 py-2 text-gray-600">${f.label}</td>
<td class="px-4 py-2 text-center font-medium">${fv1}</td>
<td class="px-4 py-2 text-center font-medium">${fv2}</td>
<td class="px-4 py-2 text-center">${diff}</td>
</tr>
`;
}).join('')}
</tbody>
</table>
`;
document.getElementById('compareTable').innerHTML = html;
document.getElementById('compareResult').classList.remove('hidden');
}
// 初始化
setCompareType('model');
</script>
</body>
</html>