185 lines
5.4 KiB
React
185 lines
5.4 KiB
React
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import { useEffectEvent } from '../../../hooks/common/useEffectEvent';
|
|
import React, { useState, useEffect } from 'react';
|
|
import { Card, Row, Col, Typography, Tag, Spin, Empty } from '@/components/ui';
|
|
import { API, showError } from '../../../helpers';
|
|
import { MODEL_CATEGORY_NAMES } from '../../../constants';
|
|
|
|
const { Title, Text } = Typography;
|
|
|
|
const ModelsCategoryStats = ({ t }) => {
|
|
const [stats, setStats] = useState({});
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const loadStats = async () => {
|
|
setLoading(true);
|
|
try {
|
|
const res = await API.get('/api/models/category-stats');
|
|
const { success, message, data } = res.data;
|
|
if (success) {
|
|
setStats(data || {});
|
|
} else {
|
|
showError(message || t('获取统计数据失败'));
|
|
}
|
|
} catch (error) {
|
|
console.error('Load category stats failed:', error);
|
|
showError(t('获取统计数据失败'));
|
|
}
|
|
setLoading(false);
|
|
};
|
|
|
|
const onMount = useEffectEvent(() => {
|
|
loadStats();
|
|
});
|
|
useEffect(() => onMount(), [onMount]);
|
|
|
|
const getCategoryColor = (category) => {
|
|
const colorMap = {
|
|
text_generation: 'blue',
|
|
image_generation: 'purple',
|
|
video_generation: 'pink',
|
|
audio_tts: 'cyan',
|
|
audio_stt: 'teal',
|
|
audio_generation: 'green',
|
|
embedding: 'violet',
|
|
multimodal: 'indigo',
|
|
rerank: 'orange',
|
|
other: 'grey',
|
|
};
|
|
return colorMap[category] || 'grey';
|
|
};
|
|
|
|
const totalModels = Object.values(stats).reduce(
|
|
(sum, count) => sum + count,
|
|
0,
|
|
);
|
|
|
|
if (loading) {
|
|
return (
|
|
<Card style={{ marginBottom: '16px' }}>
|
|
<div style={{ textAlign: 'center', padding: '20px' }}>
|
|
<Spin />
|
|
</div>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
if (totalModels === 0) {
|
|
return (
|
|
<Card style={{ marginBottom: '16px' }}>
|
|
<Empty description={t('暂无模型数据')} />
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Card
|
|
title={
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
}}
|
|
>
|
|
<Title heading={5} style={{ margin: 0 }}>
|
|
{t('模型分类统计')}
|
|
</Title>
|
|
<Tag color='blue' size='large'>
|
|
{t('总计')}: {totalModels}
|
|
</Tag>
|
|
</div>
|
|
}
|
|
style={{ marginBottom: '16px' }}
|
|
>
|
|
<Row gutter={[16, 16]}>
|
|
{Object.entries(MODEL_CATEGORY_NAMES).map(([category, name]) => {
|
|
const count = stats[category] || 0;
|
|
const percentage =
|
|
totalModels > 0 ? ((count / totalModels) * 100).toFixed(1) : 0;
|
|
|
|
return (
|
|
<Col key={category} xs={24} sm={12} md={8} lg={6} xl={4}>
|
|
<div
|
|
style={{
|
|
padding: '12px',
|
|
borderRadius: '8px',
|
|
background: 'var(--ui-color-fill-0)',
|
|
border: '1px solid var(--ui-color-border)',
|
|
transition: 'all 0.3s',
|
|
cursor: 'pointer',
|
|
}}
|
|
onMouseEnter={(e) => {
|
|
e.currentTarget.style.transform = 'translateY(-2px)';
|
|
e.currentTarget.style.boxShadow =
|
|
'0 4px 12px rgba(0,0,0,0.1)';
|
|
}}
|
|
onMouseLeave={(e) => {
|
|
e.currentTarget.style.transform = 'translateY(0)';
|
|
e.currentTarget.style.boxShadow = 'none';
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
marginBottom: '8px',
|
|
}}
|
|
>
|
|
<Tag
|
|
color={getCategoryColor(category)}
|
|
size='small'
|
|
style={{ marginRight: '8px' }}
|
|
>
|
|
{name}
|
|
</Tag>
|
|
</div>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'baseline',
|
|
}}
|
|
>
|
|
<Text
|
|
strong
|
|
style={{
|
|
fontSize: '24px',
|
|
color: 'var(--ui-color-text-0)',
|
|
}}
|
|
>
|
|
{count}
|
|
</Text>
|
|
<Text type='tertiary' size='small'>
|
|
{percentage}%
|
|
</Text>
|
|
</div>
|
|
</div>
|
|
</Col>
|
|
);
|
|
})}
|
|
</Row>
|
|
</Card>
|
|
);
|
|
};
|
|
|
|
export default ModelsCategoryStats;
|