PhysioAgent:基于 React 与 FastAPI 的可穿戴生理信号科研质控 Agent 项目

可用于可穿戴设备生理信号数据的科研质控,帮助研究人员判断数据是否适合建模或分析。项目能自动识别信号字段、检查质量、生成波形与趋势证据,并输出 Markdown/PDF 报告,非医学诊断系统。【此简介由AI生成】

Branch1Tags0

PhysioAgent

中文说明

PhysioAgent is a deterministic tool-calling agent for wearable physiological signal research quality control, trend observation, and report generation. It turns a raw PPG/ECG/ACC CSV into a reproducible research-QC workflow: field detection, signal-quality checks, waveform evidence, Moirai 2.0 trend forecasting when available, non-medical interpretation, and downloadable Markdown/PDF reports.

This project is designed for Agent-Hackathon demonstration. It is not a medical diagnosis system.

Competition Deliverables

The repository is organized against the three requested submission items:

Requirement Files in this repository
Agent source code for the code repository agent/, backend/, tools/, frontend/, scripts/, examples/, requirements.txt, run_demo.ps1, start_demo.ps1
Real-world case and value statement in README README.md and README_zh.md: project value, screenshots, sample report, built-in examples, compliance boundary, demo narrative
Deployment and usage manual in the repository README.md and README_zh.md: project-address submission notes, one-command startup, quick startup, Moirai optional setup, script explanations

If the competition platform asks for a project URL, submit the online code repository URL, not the local release zip. The repository should contain the source code, README files, deployment instructions, and demo CSV examples. releases/PhysioAgent_submit.zip is a local backup package.

One-Sentence Value

PhysioAgent helps researchers decide whether a wearable physiological signal CSV is ready for downstream analysis, and records that decision as a repeatable agent workflow instead of a scattered manual checklist.

Demo Screenshots and Sample Report

The bundled screenshots below show the recommended judging flow. A sample downloaded report is also included: PDF research-QC report.

1. Home and Data Selection

PhysioAgent home screen

2. Live Agent Progress

PhysioAgent live agent progress

3. Full Report Mode Summary

PhysioAgent full report mode summary

4. Waveform and Moirai Trend Evidence

PhysioAgent waveform and Moirai trend evidence

5. De-identified Real PPG Example

PhysioAgent real PPG result

Why This Scenario Matters

Wearable health research often begins with messy exports: unknown timestamp columns, inconsistent sampling, missing segments, motion artifacts, baseline drift, and hand-written notes scattered across notebooks. Before any model can be trusted, researchers need a fast and reproducible way to answer:

  • What signal columns are present?
  • Is the data stable enough for exploratory analysis?
  • Are missingness, short-term fluctuation, drift, or motion artifacts visible?
  • What does the trend model observe?
  • Can the result be documented for human review?

Solution

PhysioAgent wraps that workflow as a tool-calling agent. The current MVP uses a deterministic planner rather than an open-ended chatbot, which keeps the demo stable and avoids overclaiming in a health-adjacent setting.

Agent Workflow

flowchart LR
    A[Upload CSV or Choose Demo Data] --> B[Agent Planner]
    B --> C[data_loader]
    B --> D[field_detector]
    B --> E[signal_quality]
    B --> F[visualizer]
    B --> G[moirai_inference]
    B --> H[result_interpreter]
    B --> I[report_generator]
    I --> J[Markdown/PDF Research-QC Report]

The UI also shows a live Agent progress panel so the demo makes the tool calls visible instead of hiding them behind a generic dashboard.

Technical Architecture

  • frontend/: React + Vite demo UI.
  • backend/: FastAPI service exposing example listing and analysis endpoints.
  • agent/planner.py: deterministic workflow plan.
  • tools/data_loader.py: CSV loading and metadata summary.
  • tools/field_detector.py: timestamp and signal-column detection.
  • tools/signal_quality.py: missingness, outliers, short-term fluctuation, baseline drift, sampling stability, and ACC-based motion checks.
  • tools/moirai_inference.py: Moirai 2.0 trend forecasting with deterministic fallback and tail-nonstationarity index.
  • tools/result_interpreter.py: non-medical research-QC interpretation.
  • tools/report_generator.py: Markdown research-QC report content generation.
  • tools/pdf_report.py: PDF rendering for downloadable research-QC reports.
  • run_demo.ps1: one-command environment setup, dependency installation, and demo startup.
  • start_demo.ps1: quick backend/frontend startup when dependencies are already installed.

Manual Workflow vs PhysioAgent

Task Traditional Manual Workflow PhysioAgent
Field detection Inspect CSV headers manually Detect timestamp and signal columns automatically
Quality checks Write scripts for each dataset Generate quality metrics and issue summaries
Waveform review Plot signals by hand Produce waveform evidence from detected channels
Trend forecasting Run a separate model script Call Moirai 2.0 or deterministic fallback
Result interpretation Manually summarize findings Generate non-medical research-QC interpretation
Report generation Write reports by hand Generate reusable Markdown/PDF research-QC reports
Reproducibility Easy to miss steps Fixed tool chain with visible live progress

Demo Cases

Demo CSV What It Demonstrates
real_ppg_chd_preview_30s.csv De-identified 30-second real PPG preview for research-QC demonstration
synthetic_ppg_normal.csv Normal signal research-QC flow
synthetic_ppg_noisy.csv Short-term fluctuation and motion-artifact detection
synthetic_ppg_missing.csv Missing-segment detection
synthetic_ppg_drift.csv Baseline drift warning
synthetic_ecg_simple.csv ECG field detection and trend observation
synthetic_long_multichannel.csv Long sequence and multi-channel input support

Most bundled examples are generated synthetic data. The real_ppg_chd_preview_30s.csv sample is a local de-identified PPG waveform preview extracted for this demo: it keeps only time_s, normalized ppg, ppg_raw, and segment_id. It does not include uid, labels, personal identifiers, device IDs, or real acquisition timestamps, and it is not used for CHD diagnosis or risk prediction.

Moirai 2.0 Role

PhysioAgent can load Salesforce/moirai-2.0-R-small through the public Hugging Face / Uni2TS interface. Moirai is used for time-series trend forecasting and trend evidence, not disease prediction.

Moirai support is optional for portability. The submitted project does not hard-code a local D:\... path and does not include model weights. When Uni2TS or model weights are not available, PhysioAgent falls back to a deterministic linear trend baseline so the demo remains stable. Both Moirai and fallback outputs include a lightweight tail-nonstationarity index for research-QC interpretation.

Model weights are not required for the lightweight submission mode. They can be added under models/moirai-2.0-R-small/ only when creating an offline demo bundle.

Two Distribution Modes

PhysioAgent supports two competition delivery modes with the same codebase.

Project URL Submission

If the competition page asks for a project address, create an online repository on GitHub, Gitee, GitCode, ModelScope, or the competition-specified code hosting platform, then submit that repository URL.

Recommended repository contents:

  • agent/
  • backend/
  • tools/
  • frontend/
  • scripts/
  • examples/
  • docs/assets/
  • README.md
  • README_zh.md
  • requirements.txt
  • requirements-moirai.txt
  • run_demo.ps1
  • start_demo.ps1

Do not commit local package artifacts or heavyweight optional runtime bundles by default:

  • releases/
  • models/
  • vendor/
  • frontend/node_modules/
  • frontend/dist/
  • logs/, outputs/, reports/

If the platform also allows attachments, releases/PhysioAgent_submit.zip can be used as a backup source package. Use releases/PhysioAgent_offline_moirai.zip only when an offline real-Moirai demo bundle is explicitly useful and the upload size is allowed.

Mode A: Lightweight Submission

This is the safest default for source-code submission:

  • Do not include vendor/uni2ts/.
  • Do not include models/moirai-2.0-R-small/.
  • The app still runs end to end with deterministic fallback.
  • Reviewers can optionally enable real Moirai if their environment supports it.

How a reviewer enables Moirai in lightweight mode:

  1. Install the normal project dependencies:

    pip install -r requirements.txt
    
  2. Install optional Moirai dependencies:

    pip install -r requirements-moirai.txt
    
  3. Provide Uni2TS in one of three ways:

    # Option 1: point to a local Uni2TS source checkout
    .\start_demo.ps1 -Uni2tsSrc "C:\path\to\uni2ts-main\src"
    
    # Option 2: set an environment variable before backend startup
    $env:PHYSIOAGENT_UNI2TS_SRC="C:\path\to\uni2ts-main\src"
    .\start_demo.ps1
    
    # Option 3: install Uni2TS into the active Python environment
    pip install -e "C:\path\to\uni2ts-main"
    .\start_demo.ps1
    
  4. Provide Moirai 2.0 weights in one of two ways:

    # Option 1: let Hugging Face download/cache the public model
    $env:MOIRAI_MODEL_REF="Salesforce/moirai-2.0-R-small"
    .\start_demo.ps1
    
    # Option 2: point to a local downloaded model folder
    $env:MOIRAI_MODEL_REF="C:\path\to\moirai-2.0-R-small"
    .\start_demo.ps1
    

If MOIRAI_MODEL_REF is not set and no local model folder is bundled, Moirai uses the public model id Salesforce/moirai-2.0-R-small and may download/cache weights according to the reviewer's Hugging Face environment.

Mode B: Offline Moirai Demo Bundle

Use this when the competition upload allows a larger package and you want reviewers to run real Moirai without downloading model weights during judging.

On your machine, create the bundle:

.\scripts\create_moirai_offline_bundle.ps1 `
  -Uni2tsRoot "C:\path\to\uni2ts-main" `
  -WeightsRoot "C:\path\to\moirai-weights"

This creates:

  • vendor/uni2ts/: Uni2TS source code.
  • models/moirai-2.0-R-small/: local config.json and model.safetensors.

Then install optional dependencies and start normally:

pip install -r requirements-moirai.txt
.\start_demo.ps1

When these folders exist, PhysioAgent automatically prefers the bundled source and bundled model path. If optional dependencies are missing or incompatible, the app still falls back to deterministic trend inference.

To switch the same working tree back to lightweight mode:

.\scripts\remove_moirai_offline_bundle.ps1

Enabling Real Moirai Locally

If you already have the Uni2TS/Moirai source code locally, pass its src folder explicitly when starting the demo:

.\start_demo.ps1 -Uni2tsSrc "D:\Python Project\MOIRAI2.0\uni2ts-main\src"

Or set an environment variable before starting the backend:

$env:PHYSIOAGENT_UNI2TS_SRC="D:\Python Project\MOIRAI2.0\uni2ts-main\src"
python -m uvicorn backend.main:app --host 127.0.0.1 --port 8000

For a clean competition or reviewer machine, install Uni2TS according to its official project instructions, or leave it uninstalled and use the deterministic fallback path. The UI will show whether real Moirai is available.

Quick Start

One-Command Demo for Reviewers

After extracting either release zip, run:

cd /path/to/PhysioAgent
.\run_demo.ps1

run_demo.ps1 checks the local machine automatically:

  • If conda is available, it first reuses an existing physioagent environment when present; otherwise it creates or reuses physioagent-demo.
  • If conda is not available but Python 3.10+ is available, it creates or reuses a project-local .venv.
  • It installs base Python dependencies only when required modules are missing.
  • It installs frontend dependencies only when frontend/node_modules is missing.
  • It starts the FastAPI backend and Vite frontend.

If Python or Node.js is missing, the script prints the missing requirement in Chinese:

请安装 Python 3.10+
请安装 Node.js 18+

Only the actually missing requirement is printed.

For real Moirai in the offline bundle, or when manually enabling Moirai in the lightweight submission, run:

.\run_demo.ps1 -WithMoirai

Without -WithMoirai, the script skips optional Moirai dependency installation. If Moirai is unavailable, PhysioAgent automatically uses the deterministic fallback so the demo remains runnable.

Already-Installed One-Terminal Demo

cd /path/to/PhysioAgent
.\start_demo.ps1

Use start_demo.ps1 when Python and frontend dependencies are already installed. It starts the backend and frontend but does not create an isolated environment.

Then open:

http://127.0.0.1:5173

If Vite reports that 5173 is already in use, open the alternate URL printed by the terminal, such as http://127.0.0.1:5174.

Manual Backend and Frontend

Terminal 1:

conda activate physioagent
cd /path/to/PhysioAgent
# Optional: only needed when real Moirai/Uni2TS is available locally.
$env:PHYSIOAGENT_UNI2TS_SRC="/path/to/uni2ts/src"
python -m uvicorn backend.main:app --host 127.0.0.1 --port 8000

Terminal 2:

cd /path/to/PhysioAgent/frontend
npm install
npm run dev -- --port 5173

Streamlit Debug UI

The original Streamlit app remains available as a lightweight debugging surface:

cd /path/to/PhysioAgent
streamlit run app.py

Compliance and Privacy Boundary

PhysioAgent is for research quality control, trend observation, and experiment assistance only.

The project does not include:

  • Raw real personal health records. The included real PPG preview is a de-identified waveform snippet without uid or labels.
  • Project-group internal datasets.
  • Internal model weights such as MedMamba weights.
  • Real user IDs, device IDs, acquisition timestamps, blood pressure records, or heart-rate records.
  • API keys, .env files, local caches, or model checkpoints.

PhysioAgent does not provide medical diagnosis, treatment advice, disease-risk prediction, or clinical decision support. Any real health or medical deployment would require expert review, data governance, ethics approval, and rigorous validation.

Current Limitations

  • The MVP focuses on research-QC and trend observation, not clinical diagnosis.
  • The current planner is deterministic for stability and reproducibility.
  • The bundled real PPG preview is a small de-identified demonstration snippet, not a full benchmark dataset.
  • The tail-nonstationarity index is an interpretable demo metric, not a validated scientific endpoint.
  • Advanced time-frequency analysis is future work.

Future Work

  • Optional LLM-assisted explanation layer while keeping deterministic tool progress.
  • Segment-level anomaly highlighting.
  • More public-dataset adapters.
  • Batch mode for multiple CSV files.

Hackathon Submission Notes

For judging, the recommended demo path is:

  1. Start the React + FastAPI demo.
  2. Select real_ppg_chd_preview_30s.csv.
  3. Point out that it is a de-identified real PPG preview with no uid or labels.
  4. Show the task mode selector and Moirai runtime status.
  5. Run the workflow and point to the live Agent progress panel.
  6. Explain the quality metrics and Moirai tail-nonstationarity evidence.
  7. Download the Markdown or PDF research-QC report.
  8. Emphasize the compliance boundary: research-QC only, no medical diagnosis.

Introduction

可用于可穿戴设备生理信号数据的科研质控,帮助研究人员判断数据是否适合建模或分析。项目能自动识别信号字段、检查质量、生成波形与趋势证据,并输出 Markdown/PDF 报告,非医学诊断系统。【此简介由AI生成】

Customize your domain