Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
apps/src/sage/apps/medical_diagnosis/data/processed/*
apps/src/sage/apps/medical_diagnosis/data/test_results/*
apps/src/sage/apps/medical_diagnosis/data/medical/lumbar-spine-mri/cache/*
apps/src/sage/apps/medical_diagnosis/data/medical/lumbar-spine-mri/dataset_info.txt
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda",
"python-envs.pythonProjects": []
}
"python-envs.pythonProjects": [
{
"path": ".",
"envManager": "ms-python.python:conda",
"packageManager": "ms-python.python:conda"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _load_config(self, config_path: str | None) -> dict:
},
"services": {
"sagellm": {"enabled": True, "gpu_memory_utilization": 0.9},
"embedding": {"method": "hf", "cache_enabled": True},
"embedding": {"method": "hash", "cache_enabled": True},
"vector_db": {"collection_name": "lumbar_spine_cases", "top_k": 5},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:

# Embedding服务配置
embedding:
method: hf
method: hash
cache_enabled: true
normalize: true
batch_size: 32
Expand Down
5 changes: 4 additions & 1 deletion apps/src/sage/apps/medical_diagnosis/run_diagnosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from sage.apps.medical_diagnosis.agents import DiagnosticAgent


DEFAULT_CONFIG_PATH = Path(__file__).parent / "config" / "agent_config.yaml"


def check_and_setup_data(auto_setup: bool = False):
"""检查数据是否存在,如果不存在则自动下载和准备"""
# 获取当前脚本所在目录
Expand Down Expand Up @@ -120,7 +123,7 @@ def parse_args():
"--config",
"-c",
type=str,
default="examples/medical_diagnosis/config/agent_config.yaml",
default=str(DEFAULT_CONFIG_PATH),
help="配置文件路径",
)

Expand Down
9 changes: 4 additions & 5 deletions apps/src/sage/apps/medical_diagnosis/scripts/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
# Note: This script assumes sage-apps package is installed
# Install with: cd sage-apps && pip install -e .

# 查找项目根目录
_current_file = Path(__file__).resolve()
project_root = _current_file.parent.parent.parent.parent.parent.parent # 到 sage-examples 根目录
# 当前 medical_diagnosis 应用目录
APP_DIR = Path(__file__).resolve().parent.parent


# 疾病类别映射 (模拟)
Expand Down Expand Up @@ -123,8 +122,8 @@ def generate_mock_report(label: int, patient_info: dict) -> str:
def prepare_dataset():
"""准备数据集"""

dataset_path = project_root / "data" / "medical" / "lumbar-spine-mri" / "cache"
output_dir = project_root / "examples" / "medical_diagnosis" / "data" / "processed"
dataset_path = APP_DIR / "data" / "medical" / "lumbar-spine-mri" / "cache"
output_dir = APP_DIR / "data" / "processed"
output_dir.mkdir(parents=True, exist_ok=True)

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepare_dataset() now loads from APP_DIR/data/medical/.../cache, but there’s no explicit existence check before load_from_disk(...). When the dataset isn’t present (or was downloaded to a different working directory), this will raise a stack trace that’s not very actionable. Consider checking dataset_path.exists() and raising a FileNotFoundError with a message pointing to the expected location and the setup script to run.

Suggested change
if not dataset_path.exists() or not dataset_path.is_dir():
raise FileNotFoundError(
"未找到医疗数据集缓存目录。\n"
f"预期位置: {dataset_path}\n"
"请先运行 medical_diagnosis 应用的数据下载/初始化脚本,"
"确保数据集已下载到上述目录后,再重新执行本脚本。"
)

Copilot uses AI. Check for mistakes.
print("=" * 80)
Expand Down
13 changes: 7 additions & 6 deletions apps/src/sage/apps/medical_diagnosis/setup_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
DATA_DIR="$SCRIPT_DIR/data/processed"
PYTHON_BIN="${PYTHON_BIN:-python}"

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PYTHON_BIN is introduced to avoid drifting to another environment, but the early “dataset already exists” stats block still uses a hard-coded python3 -c (above). For consistency and to ensure the same interpreter is always used, switch that invocation to use $PYTHON_BIN as well.

Copilot uses AI. Check for mistakes.

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup_data.sh calls download_lumbar_dataset.py, which writes to a relative Path("data/..."), but this script never cds to $SCRIPT_DIR. If a user runs setup_data.sh from another working directory, the dataset will be downloaded to the wrong location and prepare_data.py (which reads under the app dir) won’t find it. Consider cd "$SCRIPT_DIR" early in the script (or invoke the Python scripts with an explicit working directory) to make paths robust.

Suggested change
# 确保后续 Python 脚本中的相对路径始终相对于当前应用目录解析
cd "$SCRIPT_DIR" || {
echo "❌ 无法切换到脚本目录: $SCRIPT_DIR"
exit 1
}

Copilot uses AI. Check for mistakes.
echo "=========================================="
echo "医疗诊断数据集自动设置"
Expand Down Expand Up @@ -40,7 +41,7 @@ echo ""

# 1. 安装必要的依赖
echo "1️⃣ 检查Python依赖..."
pip install -q huggingface_hub datasets pillow scikit-learn || {
"$PYTHON_BIN" -m pip install -q huggingface_hub datasets pillow scikit-learn || {
echo "❌ 依赖安装失败"
exit 1
}
Expand All @@ -49,7 +50,7 @@ echo " ✓ 依赖已安装"
# 2. 下载数据集
echo ""
echo "2️⃣ 下载腰椎MRI数据集..."
python3 "$PROJECT_ROOT/scripts/download_lumbar_dataset.py" || {
"$PYTHON_BIN" "$SCRIPT_DIR/scripts/download_lumbar_dataset.py" || {
echo "❌ 数据集下载失败"
exit 1
}
Expand All @@ -58,7 +59,7 @@ echo " ✓ 数据集下载完成"
# 3. 预处理数据
echo ""
echo "3️⃣ 预处理数据集..."
python3 "$SCRIPT_DIR/scripts/prepare_data.py" || {
"$PYTHON_BIN" "$SCRIPT_DIR/scripts/prepare_data.py" || {
echo "❌ 数据预处理失败"
exit 1
}
Expand All @@ -71,7 +72,7 @@ if [ -f "$DATA_DIR/train_index.json" ] && [ -f "$DATA_DIR/test_index.json" ]; th
echo " ✓ 数据集验证成功"

# 显示统计信息
python3 -c "
"$PYTHON_BIN" -c "
import json
with open('$DATA_DIR/stats.json', 'r') as f:
stats = json.load(f)
Expand All @@ -93,6 +94,6 @@ echo ""
echo "✅ 数据集设置完成!"
echo ""
echo "可以开始使用:"
echo " python examples/medical_diagnosis/test_diagnosis.py --mode single"
echo " python examples/medical_diagnosis/run_diagnosis.py --interactive"
echo " python apps/tests/medical_diagnosis/test_diagnosis.py --mode single"
echo " python examples/run_medical_diagnosis.py --interactive"
Comment on lines +97 to +98

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The post-setup usage hint suggests running a pytest test file directly (python apps/tests/medical_diagnosis/test_diagnosis.py ...). That file calls pytest.skip(...) and relies on pytest markers, which can behave unexpectedly when executed as a standalone script. Consider updating the message to a python -m pytest ... invocation (and/or keep the example entrypoint python examples/run_medical_diagnosis.py --interactive).

Suggested change
echo " python apps/tests/medical_diagnosis/test_diagnosis.py --mode single"
echo " python examples/run_medical_diagnosis.py --interactive"
echo " $PYTHON_BIN -m pytest apps/tests/medical_diagnosis/test_diagnosis.py"
echo " $PYTHON_BIN examples/run_medical_diagnosis.py --interactive"

Copilot uses AI. Check for mistakes.
echo ""
Loading