Repository navigation
Fix medical diagnosis data setup paths - #16
ShuhaoZhangTony merged 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the medical diagnosis demo’s data/setup pathing so dataset preparation, tests, and the example entrypoint work reliably in the existing configured (conda) environment.
Changes:
- Update
setup_data.shto usepython -m pipvia a configurable interpreter and point to in-app scripts. - Rebase medical diagnosis data read/write paths to live under the app directory (rather than repo root / examples paths).
- Switch embedding configuration defaults from
hftohashand ignore generated artifacts/caches.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/src/sage/apps/medical_diagnosis/setup_data.sh | Uses a configurable Python interpreter and updates script/data paths and printed usage hints. |
| apps/src/sage/apps/medical_diagnosis/scripts/prepare_data.py | Writes processed outputs under the medical diagnosis app directory. |
| apps/src/sage/apps/medical_diagnosis/run_diagnosis.py | Defaults config path to the in-package config/agent_config.yaml. |
| apps/src/sage/apps/medical_diagnosis/config/agent_config.yaml | Switches embedding method to hash. |
| apps/src/sage/apps/medical_diagnosis/agents/diagnostic_agent.py | Updates built-in default config to use hash embedding. |
| .vscode/settings.json | Updates VS Code Python env project configuration for conda. |
| .gitignore | Ignores additional generated test artifacts and local dataset cache files. |
| PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" | ||
| DATA_DIR="$SCRIPT_DIR/data/processed" | ||
| PYTHON_BIN="${PYTHON_BIN:-python}" | ||
|
|
There was a problem hiding this comment.
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.
| # 确保后续 Python 脚本中的相对路径始终相对于当前应用目录解析 | |
| cd "$SCRIPT_DIR" || { | |
| echo "❌ 无法切换到脚本目录: $SCRIPT_DIR" | |
| exit 1 | |
| } |
| 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}" |
There was a problem hiding this comment.
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.
| echo " python apps/tests/medical_diagnosis/test_diagnosis.py --mode single" | ||
| echo " python examples/run_medical_diagnosis.py --interactive" |
There was a problem hiding this comment.
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).
| 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" |
| dataset_path = APP_DIR / "data" / "medical" / "lumbar-spine-mri" / "cache" | ||
| output_dir = APP_DIR / "data" / "processed" | ||
| output_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
There was a problem hiding this comment.
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.
| if not dataset_path.exists() or not dataset_path.is_dir(): | |
| raise FileNotFoundError( | |
| "未找到医疗数据集缓存目录。\n" | |
| f"预期位置: {dataset_path}\n" | |
| "请先运行 medical_diagnosis 应用的数据下载/初始化脚本," | |
| "确保数据集已下载到上述目录后,再重新执行本脚本。" | |
| ) |
Summary
Fix the medical diagnosis demo so data setup and tests work correctly in the existing configured environment.
Changes
run_diagnosis.pyto use the in-package default config pathprepare_data.pyto read/write data under the medical diagnosis app directorysetup_data.shto reuse the current Python interpreter instead of drifting to another environmenthftohashValidation
Ran the following successfully in the existing conda environment:
python -m pytest -q apps/tests/test_medical_diagnosis.pypython -m pytest -q apps/tests/medical_diagnosis/test_knowledge_base.pypython -m pytest -q apps/tests/medical_diagnosis/test_image_quality.pypython -m pytest -q apps/tests/medical_diagnosis/test_image_analyzer.pySAGE_ENABLE_MEDICAL_DIAGNOSIS=1 python -m pytest -q apps/tests/medical_diagnosis/test_diagnosis.pyAlso verified:
python examples/run_medical_diagnosis.pyNotes
变更概述
修复 medical diagnosis 示例中的数据准备与路径问题,使其能够在现有已配置环境中正确完成数据生成、测试执行和示例运行。
主要修改
run_diagnosis.py的默认配置路径,改为使用应用目录内的配置文件prepare_data.py的数据读写路径,统一落到 medical diagnosis 应用目录下setup_data.sh,改为复用当前 Python 解释器,避免切到其他环境hf调整为hash验证结果
已在当前 conda 环境中完成以下验证:
python -m pytest -q apps/tests/test_medical_diagnosis.pypython -m pytest -q apps/tests/medical_diagnosis/test_knowledge_base.pypython -m pytest -q apps/tests/medical_diagnosis/test_image_quality.pypython -m pytest -q apps/tests/medical_diagnosis/test_image_analyzer.pySAGE_ENABLE_MEDICAL_DIAGNOSIS=1 python -m pytest -q apps/tests/medical_diagnosis/test_diagnosis.py另外已验证:
python examples/run_medical_diagnosis.py说明