Explorar el Código

兼容图片数据集下载

lxylxy123321 hace 17 horas
padre
commit
bb6b512ba8

+ 1 - 0
backend/app/schemas/dataset.py

@@ -27,6 +27,7 @@ class DatasetDownloadRequest(BaseModel):
 class DatasetDownloadResponse(BaseModel):
     dataset_id: str
     status: str  # "downloading" | "completed" | "failed"
+    task_id: str
     path: str | None = None
     error: str | None = None
 

+ 9 - 4
backend/app/services/dataset_service.py

@@ -97,7 +97,7 @@ async def download_dataset(req: DatasetDownloadRequest) -> DatasetDownloadRespon
 
     logger.info(f"Dataset download task started: {req.dataset_id} (task_id={task_id})")
     return DatasetDownloadResponse(
-        dataset_id=req.dataset_id, status="pending", path=task_id
+        dataset_id=req.dataset_id, status="pending", task_id=task_id, path=task_id
     )
 
 
@@ -301,9 +301,12 @@ def _download_modelscope_dataset(dataset_id: str) -> tuple[Path, Path, int]:
             try:
                 records.append(json.loads(line))
             except json.JSONDecodeError:
-                records = json.loads(content)
-                if not isinstance(records, list):
-                    records = [records]
+                # 单行解析失败,尝试整体解析
+                try:
+                    data = json.loads(content)
+                    records = data if isinstance(data, list) else [data]
+                except json.JSONDecodeError:
+                    records = []
                 break
     elif target.suffix == ".json":
         # JSON 文件:先尝试 JSON 数组,失败再逐行解析(可能是 JSONL 格式)
@@ -321,6 +324,8 @@ def _download_modelscope_dataset(dataset_id: str) -> tuple[Path, Path, int]:
                     records.append(json.loads(line))
                 except json.JSONDecodeError:
                     continue
+    else:
+        records = []
 
     with open(jsonl_path, "w", encoding="utf-8") as f:
         for item in records:

+ 1 - 0
frontend/src/api/client.ts

@@ -285,6 +285,7 @@ interface DatasetInfo {
 interface DatasetDownloadResponse {
   dataset_id: string
   status: string
+  task_id: string
   path?: string
   error?: string
 }