|
|
@@ -4,10 +4,16 @@ import api, { DatasetInfo } from '../api/client'
|
|
|
export function Datasets() {
|
|
|
const [datasets, setDatasets] = useState<DatasetInfo[]>([])
|
|
|
const [uploading, setUploading] = useState(false)
|
|
|
+ const [downloading, setDownloading] = useState(false)
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
const [previewData, setPreviewData] = useState<{ columns: string[]; rows: { row_index: number; data: Record<string, unknown> }[] } | null>(null)
|
|
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
|
|
|
|
+ // Download form
|
|
|
+ const [dlDatasetId, setDlDatasetId] = useState('')
|
|
|
+ const [dlUseModelscope, setDlUseModelscope] = useState(false)
|
|
|
+ const [dlStatus, setDlStatus] = useState('')
|
|
|
+
|
|
|
const fetchDatasets = () => {
|
|
|
setLoading(true)
|
|
|
api.datasets.list()
|
|
|
@@ -33,6 +39,16 @@ export function Datasets() {
|
|
|
if (file) handleFileUpload(file)
|
|
|
}
|
|
|
|
|
|
+ const handleDownload = () => {
|
|
|
+ if (!dlDatasetId.trim()) return
|
|
|
+ setDownloading(true)
|
|
|
+ setDlStatus('正在下载...')
|
|
|
+ api.datasets.download(dlDatasetId, dlUseModelscope)
|
|
|
+ .then(res => setDlStatus(`${res.dataset_id}: ${res.status}${res.error ? ` - ${res.error}` : ''}`))
|
|
|
+ .catch(err => setDlStatus(`下载失败: ${err.message}`))
|
|
|
+ .finally(() => setDownloading(false))
|
|
|
+ }
|
|
|
+
|
|
|
const handlePreview = (id: string) => {
|
|
|
api.datasets.preview(id, 10)
|
|
|
.then(res => setPreviewData({ columns: res.columns, rows: res.preview_rows }))
|
|
|
@@ -73,6 +89,32 @@ export function Datasets() {
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
+ {/* Download section */}
|
|
|
+ <div style={{ marginTop: 24 }}>
|
|
|
+ <h2 style={{ margin: '0 0 12px', fontSize: 16 }}>从平台下载</h2>
|
|
|
+ <div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ placeholder="数据集 ID (如 glue, MRPC, stanfordnlp/imdb)"
|
|
|
+ value={dlDatasetId}
|
|
|
+ onChange={e => setDlDatasetId(e.target.value)}
|
|
|
+ style={{ padding: '8px 12px', width: 400, borderRadius: 4, border: '1px solid #ccc' }}
|
|
|
+ />
|
|
|
+ <label style={{ fontSize: 13, color: '#666', whiteSpace: 'nowrap' }}>
|
|
|
+ <input type="checkbox" checked={dlUseModelscope} onChange={e => setDlUseModelscope(e.target.checked)} />
|
|
|
+ {' '}ModelScope
|
|
|
+ </label>
|
|
|
+ <button
|
|
|
+ onClick={handleDownload}
|
|
|
+ disabled={downloading}
|
|
|
+ style={{ padding: '8px 16px', borderRadius: 4, border: 'none', background: '#e94560', color: '#fff', cursor: 'pointer', opacity: downloading ? 0.6 : 1 }}
|
|
|
+ >
|
|
|
+ {downloading ? '下载中...' : '下载数据集'}
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ {dlStatus && <p style={{ marginTop: 8, fontSize: 13, color: dlStatus.includes('failed') || dlStatus.includes('失败') ? '#e94560' : '#666' }}>{dlStatus}</p>}
|
|
|
+ </div>
|
|
|
+
|
|
|
{/* Dataset list */}
|
|
|
<div style={{ marginTop: 24 }}>
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
|