chenchaoyun
commited on
Commit
·
ca12963
1
Parent(s):
7c323a5
fix
Browse files- api_routes.py +28 -1
api_routes.py
CHANGED
|
@@ -6,6 +6,7 @@ import inspect
|
|
| 6 |
import io
|
| 7 |
import json
|
| 8 |
import os
|
|
|
|
| 9 |
import time
|
| 10 |
import uuid
|
| 11 |
import subprocess
|
|
@@ -3526,23 +3527,48 @@ def _extract_tar_archive(archive_path: str, target_dir: str) -> Dict[str, str]:
|
|
| 3526 |
}
|
| 3527 |
|
| 3528 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3529 |
def extract_chinese_celeb_dataset_sync() -> Dict[str, Any]:
|
| 3530 |
"""
|
| 3531 |
同步执行 chinese_celeb_dataset 解压操作,供启动流程或其他同步场景复用。
|
| 3532 |
"""
|
| 3533 |
archive_path = os.path.join(MODELS_PATH, "chinese_celeb_dataset.tar.gz")
|
| 3534 |
-
target_dir = "/opt/data"
|
| 3535 |
|
| 3536 |
if not os.path.isfile(archive_path):
|
| 3537 |
raise FileNotFoundError(f"数据集文件不存在: {archive_path}")
|
| 3538 |
|
| 3539 |
try:
|
|
|
|
|
|
|
| 3540 |
os.makedirs(target_dir, exist_ok=True)
|
| 3541 |
except OSError as exc:
|
| 3542 |
logger.error(f"创建目标目录失败: {target_dir}, {exc}")
|
| 3543 |
raise RuntimeError(f"创建目标目录失败: {exc}") from exc
|
| 3544 |
|
| 3545 |
extract_result = _extract_tar_archive(archive_path, target_dir)
|
|
|
|
|
|
|
| 3546 |
return {
|
| 3547 |
"success": True,
|
| 3548 |
"message": "chinese_celeb_dataset 解压完成",
|
|
@@ -3551,6 +3577,7 @@ def extract_chinese_celeb_dataset_sync() -> Dict[str, Any]:
|
|
| 3551 |
"command": extract_result.get("command"),
|
| 3552 |
"stdout": extract_result.get("stdout"),
|
| 3553 |
"stderr": extract_result.get("stderr"),
|
|
|
|
| 3554 |
}
|
| 3555 |
|
| 3556 |
|
|
|
|
| 6 |
import io
|
| 7 |
import json
|
| 8 |
import os
|
| 9 |
+
import shutil
|
| 10 |
import time
|
| 11 |
import uuid
|
| 12 |
import subprocess
|
|
|
|
| 3527 |
}
|
| 3528 |
|
| 3529 |
|
| 3530 |
+
def _flatten_chinese_celeb_dataset_dir(target_dir: str) -> bool:
|
| 3531 |
+
"""
|
| 3532 |
+
若解压后出现 /opt/data/... 的嵌套结构,将内容提升到 target_dir 根目录,避免重复嵌套。
|
| 3533 |
+
"""
|
| 3534 |
+
nested_root = os.path.join(target_dir, "opt", "data", "chinese_celeb_dataset")
|
| 3535 |
+
if not os.path.isdir(nested_root):
|
| 3536 |
+
return False
|
| 3537 |
+
|
| 3538 |
+
for name in os.listdir(nested_root):
|
| 3539 |
+
src = os.path.join(nested_root, name)
|
| 3540 |
+
dst = os.path.join(target_dir, name)
|
| 3541 |
+
shutil.move(src, dst)
|
| 3542 |
+
|
| 3543 |
+
# 清理多余的 opt/data 目录
|
| 3544 |
+
try:
|
| 3545 |
+
shutil.rmtree(os.path.join(target_dir, "opt"))
|
| 3546 |
+
except FileNotFoundError:
|
| 3547 |
+
pass
|
| 3548 |
+
return True
|
| 3549 |
+
|
| 3550 |
+
|
| 3551 |
def extract_chinese_celeb_dataset_sync() -> Dict[str, Any]:
|
| 3552 |
"""
|
| 3553 |
同步执行 chinese_celeb_dataset 解压操作,供启动流程或其他同步场景复用。
|
| 3554 |
"""
|
| 3555 |
archive_path = os.path.join(MODELS_PATH, "chinese_celeb_dataset.tar.gz")
|
| 3556 |
+
target_dir = "/opt/data/chinese_celeb_dataset"
|
| 3557 |
|
| 3558 |
if not os.path.isfile(archive_path):
|
| 3559 |
raise FileNotFoundError(f"数据集文件不存在: {archive_path}")
|
| 3560 |
|
| 3561 |
try:
|
| 3562 |
+
if os.path.isdir(target_dir):
|
| 3563 |
+
shutil.rmtree(target_dir)
|
| 3564 |
os.makedirs(target_dir, exist_ok=True)
|
| 3565 |
except OSError as exc:
|
| 3566 |
logger.error(f"创建目标目录失败: {target_dir}, {exc}")
|
| 3567 |
raise RuntimeError(f"创建目标目录失败: {exc}") from exc
|
| 3568 |
|
| 3569 |
extract_result = _extract_tar_archive(archive_path, target_dir)
|
| 3570 |
+
flattened = _flatten_chinese_celeb_dataset_dir(target_dir)
|
| 3571 |
+
|
| 3572 |
return {
|
| 3573 |
"success": True,
|
| 3574 |
"message": "chinese_celeb_dataset 解压完成",
|
|
|
|
| 3577 |
"command": extract_result.get("command"),
|
| 3578 |
"stdout": extract_result.get("stdout"),
|
| 3579 |
"stderr": extract_result.get("stderr"),
|
| 3580 |
+
"normalized": flattened,
|
| 3581 |
}
|
| 3582 |
|
| 3583 |
|