Skip to content

Fix medical diagnosis data setup paths - #16

Merged
ShuhaoZhangTony merged 1 commit into
RIDE-Lab:mainfrom
kms12425-ctrl:feature/medical-diagnosis-path-fix
Apr 19, 2026
Merged

ShuhaoZhangTony merged 1 commit into
RIDE-Lab:mainfrom
kms12425-ctrl:feature/medical-diagnosis-path-fix

Conversation

@kms12425-ctrl

Copy link
Copy Markdown
Contributor

Summary

Fix the medical diagnosis demo so data setup and tests work correctly in the existing configured environment.

Changes

  • fix run_diagnosis.py to use the in-package default config path
  • fix prepare_data.py to read/write data under the medical diagnosis app directory
  • fix setup_data.sh to reuse the current Python interpreter instead of drifting to another environment
  • update medical diagnosis embedding config from hf to hash
  • ignore generated medical test artifacts and local dataset cache

Validation

Ran the following successfully in the existing conda environment:

  • python -m pytest -q apps/tests/test_medical_diagnosis.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_knowledge_base.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_image_quality.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_image_analyzer.py
  • SAGE_ENABLE_MEDICAL_DIAGNOSIS=1 python -m pytest -q apps/tests/medical_diagnosis/test_diagnosis.py

Also verified:

  • python examples/run_medical_diagnosis.py

Notes

  • The example still falls back when the local LLM service is unavailable, but the diagnosis flow completes correctly.

变更概述

修复 medical diagnosis 示例中的数据准备与路径问题,使其能够在现有已配置环境中正确完成数据生成、测试执行和示例运行。

主要修改

  • 修复 run_diagnosis.py 的默认配置路径,改为使用应用目录内的配置文件
  • 修复 prepare_data.py 的数据读写路径,统一落到 medical diagnosis 应用目录下
  • 修复 setup_data.sh,改为复用当前 Python 解释器,避免切到其他环境
  • 将 medical diagnosis 的 embedding 配置从 hf 调整为 hash
  • 补充忽略规则,避免将本地生成的数据缓存和测试产物误提交

验证结果

已在当前 conda 环境中完成以下验证:

  • python -m pytest -q apps/tests/test_medical_diagnosis.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_knowledge_base.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_image_quality.py
  • python -m pytest -q apps/tests/medical_diagnosis/test_image_analyzer.py
  • SAGE_ENABLE_MEDICAL_DIAGNOSIS=1 python -m pytest -q apps/tests/medical_diagnosis/test_diagnosis.py

另外已验证:

  • python examples/run_medical_diagnosis.py

说明

  • 当本地 LLM 服务不可用时,示例仍会回退到模板报告生成,但整体诊断流程可以正常完成。
  • 本次修改未创建新的虚拟环境,全部验证均基于现有 conda 环境完成。

Copilot AI review requested due to automatic review settings April 18, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.sh to use python -m pip via 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 hf to hash and 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}"

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.
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.
Comment on lines +97 to +98
echo " python apps/tests/medical_diagnosis/test_diagnosis.py --mode single"
echo " python examples/run_medical_diagnosis.py --interactive"

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.
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.
@ShuhaoZhangTony
ShuhaoZhangTony merged commit 6d5679e into RIDE-Lab:main Apr 19, 2026
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants