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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- Qwen/Qwen3.6-27B
|
| 7 |
+
- Qwen/Qwen3.6-35B-A3B
|
| 8 |
+
pipeline_tag: image-to-text
|
| 9 |
+
tags:
|
| 10 |
+
- medical
|
| 11 |
+
---
|
| 12 |
+
<div align="center">
|
| 13 |
+
|
| 14 |
+
<img src="https://img.shields.io/badge/AMD_Instinct-MI300X-ED1C24?style=for-the-badge&logo=amd&logoColor=white" />
|
| 15 |
+
<img src="https://img.shields.io/badge/ROCm-Stack-ED1C24?style=for-the-badge&logo=amd&logoColor=white" />
|
| 16 |
+
<img src="https://img.shields.io/badge/vLLM-Inference-6D28D9?style=for-the-badge" />
|
| 17 |
+
<img src="https://img.shields.io/badge/Qwen-Multimodal-0EA5E9?style=for-the-badge" />
|
| 18 |
+
<img src="https://img.shields.io/badge/FastAPI-0.115-009688?style=for-the-badge&logo=fastapi&logoColor=white" />
|
| 19 |
+
<img src="https://img.shields.io/badge/Python-3.12+-3776AB?style=for-the-badge&logo=python&logoColor=white" />
|
| 20 |
+
|
| 21 |
+
<br /><br />
|
| 22 |
+
|
| 23 |
+
# π₯ MediAgent
|
| 24 |
+
|
| 25 |
+
### Autonomous Multi-Agent Medical Imaging Analysis System
|
| 26 |
+
|
| 27 |
+
**Five specialized AI agents. One radiological verdict. Running entirely on AMD.**
|
| 28 |
+
|
| 29 |
+
*AMD Developer Hackathon 2026 Β· Track: Vision & Multimodal AI*
|
| 30 |
+
|
| 31 |
+
<br />
|
| 32 |
+
|
| 33 |
+
> Built by **Ramyar** β Security researcher & full-stack developer, Sulaymaniyah, Iraq
|
| 34 |
+
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## What Is MediAgent?
|
| 40 |
+
|
| 41 |
+
MediAgent is a production-grade autonomous AI system that analyzes medical images β X-rays, MRI scans, CT scans β through a five-agent pipeline and generates structured, peer-reviewed clinical radiology reports in real time.
|
| 42 |
+
|
| 43 |
+
Upload an image. Watch five AI agents execute live. Get a formal radiology report with differential diagnoses, ICD-10 codes, a quality score, and a FHIR R4 export ready for any EMR system.
|
| 44 |
+
|
| 45 |
+
**No cloud APIs. No OpenAI. No Nvidia.**
|
| 46 |
+
Pure AMD MI300X inference. Local. Private. Fast.
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## The Pipeline
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
+
β IMAGE UPLOAD β
|
| 55 |
+
β PNG / JPG / DICOM (.dcm) β up to 20 MB β
|
| 56 |
+
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
|
| 57 |
+
β
|
| 58 |
+
ββββββββββββββββββ΄βββββββββββββββββ
|
| 59 |
+
β PARALLEL STAGE β
|
| 60 |
+
βΌ βΌ
|
| 61 |
+
βββββββββββββββββββ βββββββββββββββββββ
|
| 62 |
+
β INTAKE AGENT β β VISION AGENT β
|
| 63 |
+
β β β β
|
| 64 |
+
β β’ Validates β β β’ Multimodal β
|
| 65 |
+
β image payload β β Qwen analysis β
|
| 66 |
+
β β’ Normalizes β β β’ Anatomical β
|
| 67 |
+
β clinical text β β findings β
|
| 68 |
+
β β’ Extracts β β β’ Severity per β
|
| 69 |
+
β demographics β β region β
|
| 70 |
+
β β’ Safety triage β β β’ Confidence β
|
| 71 |
+
β (16 keywords) β β scoring β
|
| 72 |
+
β β’ Modality hint β β β’ Anomaly flags β
|
| 73 |
+
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
|
| 74 |
+
ββββββββββββββββ¬βββββββββββββββββββ
|
| 75 |
+
β
|
| 76 |
+
βΌ
|
| 77 |
+
βββββββββββββββββββββββββ
|
| 78 |
+
β RESEARCH AGENT β
|
| 79 |
+
β β
|
| 80 |
+
β β’ KB cross-reference β
|
| 81 |
+
β (15 conditions) β
|
| 82 |
+
β β’ Demographic weight β
|
| 83 |
+
β β’ Ranked differentialsβ
|
| 84 |
+
β β’ ICD-10 codes β
|
| 85 |
+
β β’ Match probabilities β
|
| 86 |
+
βββββββββββββ¬ββββββββββββ
|
| 87 |
+
β
|
| 88 |
+
βΌ
|
| 89 |
+
βββββββββββββββββββββββββ
|
| 90 |
+
β REPORT AGENT β
|
| 91 |
+
β β
|
| 92 |
+
β β’ ACR/NICE format β
|
| 93 |
+
β β’ Clinical history β
|
| 94 |
+
β β’ Technique section β
|
| 95 |
+
β β’ Findings narrative β
|
| 96 |
+
β β’ Impression + top Dx β
|
| 97 |
+
β β’ Recommendations β
|
| 98 |
+
βββββββββββββ¬ββββββββββββ
|
| 99 |
+
β
|
| 100 |
+
βΌ
|
| 101 |
+
βββββββββββββββββββββββββ
|
| 102 |
+
β CRITIC AGENT β
|
| 103 |
+
β β
|
| 104 |
+
β β’ Cross-validates β
|
| 105 |
+
β report vs findings β
|
| 106 |
+
β β’ Quality score 0-100 β
|
| 107 |
+
β β’ Uncertainty flags β
|
| 108 |
+
β β’ Disclaimer enforce β
|
| 109 |
+
βββββββββββββ¬ββββββββββββ
|
| 110 |
+
β
|
| 111 |
+
βΌ
|
| 112 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 113 |
+
β FINAL REPORT β
|
| 114 |
+
β Structured JSON Β· PDF Export Β· FHIR R4 DiagnosticReport β
|
| 115 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
INTAKE and VISION execute **concurrently** β cutting wall-clock latency by running the two most expensive operations in parallel. Everything downstream sequences after both complete.
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## AMD Hardware Stack
|
| 123 |
+
|
| 124 |
+
| Component | Technology |
|
| 125 |
+
|---|---|
|
| 126 |
+
| **GPU** | AMD Instinct MI300X |
|
| 127 |
+
| **GPU Software** | ROCm β AMD's open-source GPU compute platform |
|
| 128 |
+
| **Inference Server** | vLLM (ROCm build) at `localhost:8000/v1` |
|
| 129 |
+
| **Model** | Qwen multimodal β native vision + text |
|
| 130 |
+
| **Backend** | FastAPI 0.115 + Uvicorn |
|
| 131 |
+
| **Frontend** | Vanilla JS + Tailwind CSS + SSE streaming |
|
| 132 |
+
|
| 133 |
+
This project is a direct proof of concept that AMD's ROCm stack is **production-viable for real-world medical AI**. Every inference call β vision analysis, clinical normalization, report synthesis, peer review, post-report chat β runs on AMD MI300X. Zero CUDA dependency. Zero cloud API calls.
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## Key Features
|
| 138 |
+
|
| 139 |
+
### π΄ Real-Time SSE Streaming
|
| 140 |
+
Watch the pipeline execute live, agent by agent. Every status transition β WAITING β RUNNING β DONE β streams to the dashboard as it happens via Server-Sent Events. Per-agent runtime counters track exactly how long each step takes.
|
| 141 |
+
|
| 142 |
+
### ποΈ Multimodal Vision Analysis
|
| 143 |
+
Qwen processes the raw medical image natively. It returns structured JSON: detected modality, technical quality assessment, per-region findings with anatomical names, radiological descriptions, severity levels (NORMAL / INCIDENTAL / SIGNIFICANT / CRITICAL), confidence scores (0β100), and anomaly flags.
|
| 144 |
+
|
| 145 |
+
### π¬ Medical Knowledge Base + ICD-10 Mapping
|
| 146 |
+
The Research Agent cross-references vision findings against 15 curated clinical conditions spanning pulmonary, neurological, abdominal, musculoskeletal, and vascular pathology. Every differential diagnosis comes with an ICD-10 code, match probability, and a sentence explaining exactly why the condition matches the findings.
|
| 147 |
+
|
| 148 |
+
### π‘οΈ Critic Agent QA
|
| 149 |
+
Every report goes through a peer-review pass before delivery. The Critic checks that all anomalies from the Vision Agent appear in the report, flags low-confidence findings, assigns a quality score (completeness 30% + accuracy 40% + safety 20% + compliance 10%), and hard-caps the score at 40/100 if a core agent failed.
|
| 150 |
+
|
| 151 |
+
### π₯ DICOM Support
|
| 152 |
+
Upload real `.dcm` files. MediAgent extracts 20+ metadata fields β patient name, study date, institution, modality, body part, KVP, slice thickness, pixel spacing, image dimensions β and pre-populates the intake form automatically. MONOCHROME1 inversion and multi-frame handling included.
|
| 153 |
+
|
| 154 |
+
### π FHIR R4 Export
|
| 155 |
+
Every report can be exported as a fully conformant HL7 FHIR R4 DiagnosticReport resource. Includes an inline Patient resource, Observation resources, LOINC and SNOMED CT codes, severity mapping, full report text in `presentedForm`, and custom extensions for AI quality score and pipeline status. Ready to import into Epic, Cerner, or any FHIR-capable EMR.
|
| 156 |
+
|
| 157 |
+
### π¬ Post-Report Clinical Chat
|
| 158 |
+
After the report is delivered, a ClinicalAdvisorAgent is available for follow-up questions. It answers in 2β4 sentences with direct reference to the report findings. Qwen's thinking/reasoning mode is explicitly disabled β answers are fast, direct, and clinical.
|
| 159 |
+
|
| 160 |
+
### π Hard Safety Enforcement
|
| 161 |
+
- **16 deterministic safety keywords** β chest pain, stroke symptoms, acute trauma, hemoptysis, sepsis, spinal trauma, and more β trigger urgent flags regardless of LLM output.
|
| 162 |
+
- **Age-based alerts** β pediatric (<18) and geriatric (>75) cases are automatically flagged for expert review.
|
| 163 |
+
- **Mandatory AI disclaimer** β enforced at two independent layers (Report Agent + Critic Agent) and cannot be bypassed or modified by the LLM.
|
| 164 |
+
- **Graceful degradation** β the pipeline produces a report even if individual agents fail, always marking what succeeded and what didn't.
|
| 165 |
+
|
| 166 |
+
### π Client-Side PDF Export
|
| 167 |
+
Full radiology report exported as a formatted PDF directly in the browser using jsPDF β severity color banner, all six report sections, DICOM metadata, QA score. No server round-trip needed.
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
## Agent Architecture
|
| 172 |
+
|
| 173 |
+
### IntakeAgent
|
| 174 |
+
Validates the image payload (minimum size, valid base64), applies deterministic safety triage, and normalizes clinical language. For simple inputs under 120 characters it skips the LLM entirely and uses a built-in layman-to-medical term map (22 entries: "can't breathe" β "dyspnea", "lump" β "mass/nodule", "dizzy" β "dizziness/vertigo", etc.). Only calls the LLM for complex clinical narratives with comorbidities or medical history. Falls back cleanly to raw input preservation if the LLM is unavailable.
|
| 175 |
+
|
| 176 |
+
### VisionAgent
|
| 177 |
+
Sends the base64 image and clinical context to Qwen at temperature 0.0 with a strict JSON schema enforced via system prompt. Handles malformed enum values from the LLM with safe conversion fallbacks β a single bad field never drops a finding. Tracks token usage and anomaly counts in the output metadata.
|
| 178 |
+
|
| 179 |
+
### ResearchAgent
|
| 180 |
+
Pre-filters the knowledge base to only conditions compatible with the detected modality before sending to the LLM β reducing prompt size and improving accuracy. Enforces strict output rules: only conditions from the KB, 2β4 differentials maximum, 5% minimum probability, exact ICD-10 codes, and evidence sentences that actually explain the match.
|
| 181 |
+
|
| 182 |
+
### ReportAgent
|
| 183 |
+
Builds a structured prompt with clearly labeled sections β clinical history, imaging technique, findings block, differentials block β and asks the LLM to synthesize them into a formal ACR/NICE radiology report. The disclaimer is overwritten to the exact regulatory string after LLM generation, unconditionally.
|
| 184 |
+
|
| 185 |
+
### CriticAgent
|
| 186 |
+
Operates at temperature 0.0 for fully deterministic QA. Receives the draft report and the full pipeline state including raw vision findings. Checks every anomaly is accounted for, flags low-confidence observations, and appends a `[QUALITY ASSESSMENT]` block to the recommendations section with score, issues, and uncertainty warnings.
|
| 187 |
+
|
| 188 |
+
### ClinicalAdvisorAgent
|
| 189 |
+
Activated only after report delivery, scoped to the specific report's findings. Strips all Qwen thinking output via multi-layer regex before returning the answer β handles `<think>` XML blocks, markdown think fences, and plain-text reasoning preambles.
|
| 190 |
+
|
| 191 |
+
---
|
| 192 |
+
|
| 193 |
+
## LLM Client
|
| 194 |
+
|
| 195 |
+
The `LLMClient` wraps the OpenAI Python SDK pointed at the local vLLM endpoint. It handles:
|
| 196 |
+
|
| 197 |
+
- Text completions with optional JSON mode enforcement
|
| 198 |
+
- Multimodal completions with base64 image injection
|
| 199 |
+
- Token-level streaming with an `on_token` callback
|
| 200 |
+
- 3-attempt retry loop with 1-second flat backoff
|
| 201 |
+
- 90-second timeout per call
|
| 202 |
+
- Dual-strategy JSON extraction: direct parse first, then character-by-character brace-matching fallback for responses where the LLM adds conversational padding
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
## Medical Knowledge Base
|
| 207 |
+
|
| 208 |
+
15 conditions covering the most common radiological findings across all supported modalities:
|
| 209 |
+
|
| 210 |
+
| Condition | ICD-10 | Modalities | Severity |
|
| 211 |
+
|---|---|---|---|
|
| 212 |
+
| Community-Acquired Pneumonia | J18.9 | X-RAY, CT | SIGNIFICANT |
|
| 213 |
+
| Cardiogenic Pulmonary Edema | J81.0 | X-RAY, CT | CRITICAL |
|
| 214 |
+
| Pleural Effusion | J90 | X-RAY, CT, MRI | SIGNIFICANT |
|
| 215 |
+
| Spontaneous Pneumothorax | J93.9 | X-RAY, CT | CRITICAL |
|
| 216 |
+
| Intracerebral Hemorrhage | I61.9 | CT, MRI | CRITICAL |
|
| 217 |
+
| Ischemic Stroke | I63.9 | CT, MRI | CRITICAL |
|
| 218 |
+
| Intracranial Neoplasm | C71.9 | MRI, CT | SIGNIFICANT |
|
| 219 |
+
| Abdominal Aortic Aneurysm | I71.4 | CT, MRI | CRITICAL |
|
| 220 |
+
| Nephrolithiasis | N20.0 | CT, X-RAY | SIGNIFICANT |
|
| 221 |
+
| Small Bowel Obstruction | K56.6 | X-RAY, CT | SIGNIFICANT |
|
| 222 |
+
| Long Bone Fracture | S82.902 | X-RAY, CT | SIGNIFICANT |
|
| 223 |
+
| Degenerative Joint Disease | M19.90 | X-RAY, MRI | INCIDENTAL |
|
| 224 |
+
| Hepatic Steatosis | K76.0 | CT, MRI | INCIDENTAL |
|
| 225 |
+
| Herniated Disc | M51.16 | MRI, CT | SIGNIFICANT |
|
| 226 |
+
| Pulmonary Nodule | R91.1 | X-RAY, CT | SIGNIFICANT |
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## API Reference
|
| 231 |
+
|
| 232 |
+
| Method | Endpoint | Description |
|
| 233 |
+
|---|---|---|
|
| 234 |
+
| `GET` | `/` | Clinical dashboard UI |
|
| 235 |
+
| `GET` | `/health` | System health, version, active sessions |
|
| 236 |
+
| `GET` | `/metrics/gpu` | Live AMD GPU metrics (util, VRAM, temp, power) |
|
| 237 |
+
| `POST` | `/analyze` | Synchronous pipeline β full JSON report |
|
| 238 |
+
| `POST` | `/analyze/stream` | Real-time SSE streaming pipeline |
|
| 239 |
+
| `GET` | `/status/{report_id}` | Poll live pipeline state |
|
| 240 |
+
| `POST` | `/chat/{report_id}` | Post-report clinical Q&A |
|
| 241 |
+
| `GET` | `/api/docs` | Swagger UI |
|
| 242 |
+
| `GET` | `/api/redoc` | ReDoc UI |
|
| 243 |
+
|
| 244 |
+
### `/analyze/stream` β SSE Event Types
|
| 245 |
+
|
| 246 |
+
```json
|
| 247 |
+
// Agent status update (emitted on every state transition)
|
| 248 |
+
{"agent": "VISION", "status": "RUNNING"}
|
| 249 |
+
{"agent": "VISION", "status": "DONE"}
|
| 250 |
+
|
| 251 |
+
// Final report (emitted when pipeline completes)
|
| 252 |
+
{"type": "report", "data": {...}, "report_id": "REP-A3F9C2D1B4E7"}
|
| 253 |
+
|
| 254 |
+
// Error
|
| 255 |
+
{"type": "error", "message": "Pipeline produced no report"}
|
| 256 |
+
```
|
| 257 |
+
|
| 258 |
+
### Form Fields (`/analyze`, `/analyze/stream`)
|
| 259 |
+
|
| 260 |
+
| Field | Type | Required | Notes |
|
| 261 |
+
|---|---|---|---|
|
| 262 |
+
| `image` | File | β
| PNG, JPG, or DICOM (.dcm), max 20 MB |
|
| 263 |
+
| `symptoms` | string | β | Free-text chief complaint |
|
| 264 |
+
| `age` | integer | β | 0β120 |
|
| 265 |
+
| `sex` | string | β | `M`, `F`, or `O` |
|
| 266 |
+
| `clinical_context` | string | β | Medical history, referral details |
|
| 267 |
+
|
| 268 |
+
---
|
| 269 |
+
|
| 270 |
+
## Data Models
|
| 271 |
+
|
| 272 |
+
```
|
| 273 |
+
PatientInput
|
| 274 |
+
βββ image_base64, symptoms, age, sex, clinical_context
|
| 275 |
+
|
| 276 |
+
PipelineState
|
| 277 |
+
βββ agent_statuses: {INTAKE, VISION, RESEARCH, REPORT, CRITIC}
|
| 278 |
+
βββ intake_output: IntakeOutput
|
| 279 |
+
βββ vision_output: VisionOutput
|
| 280 |
+
β βββ findings: [VisionFinding, ...]
|
| 281 |
+
β βββ anatomical_region, description, severity,
|
| 282 |
+
β confidence, confidence_score, is_anomaly
|
| 283 |
+
βββ research_output: ResearchOutput
|
| 284 |
+
β βββ differential_diagnoses: [KnowledgeMatch, ...]
|
| 285 |
+
β βββ condition_name, match_probability,
|
| 286 |
+
β supporting_evidence, differential_rank, icd10_code
|
| 287 |
+
βββ report_draft: ReportSection
|
| 288 |
+
β βββ clinical_history, technique, findings, impression,
|
| 289 |
+
β recommendations, disclaimer
|
| 290 |
+
βββ final_report: FinalReport
|
| 291 |
+
βββ report_id, patient_metadata, sections, vision_summary,
|
| 292 |
+
research_summary, overall_severity, agent_pipeline_status,
|
| 293 |
+
generation_timestamp
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
---
|
| 297 |
+
|
| 298 |
+
## Project Structure
|
| 299 |
+
|
| 300 |
+
```
|
| 301 |
+
mediagent/
|
| 302 |
+
βββ main.py β FastAPI server, all routes, SSE orchestration
|
| 303 |
+
βββ core/
|
| 304 |
+
β βββ llm.py β LLM client (retry, vision, streaming, JSON extraction)
|
| 305 |
+
β βββ models.py β All Pydantic v2 data models
|
| 306 |
+
β βββ pipeline.py β Parallel pipeline orchestrator
|
| 307 |
+
β βββ dicom.py β DICOM parser (pydicom + numpy + Pillow)
|
| 308 |
+
β βββ fhir.py β FHIR R4 DiagnosticReport builder
|
| 309 |
+
βββ agents/
|
| 310 |
+
β βββ intake.py β Input validation, normalization, safety triage
|
| 311 |
+
β βββ vision.py β Multimodal image analysis
|
| 312 |
+
β βββ research.py β KB matching, ICD-10, differential diagnosis
|
| 313 |
+
β βββ report.py β ACR/NICE radiology report synthesis
|
| 314 |
+
β βββ critic.py β QA validation, quality scoring
|
| 315 |
+
β βββ advisor.py β Post-report clinical Q&A
|
| 316 |
+
βββ static/
|
| 317 |
+
β βββ index.html β Full dashboard (Tailwind + Chart.js + SSE)
|
| 318 |
+
βββ requirements.txt
|
| 319 |
+
βββ .env.example
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
---
|
| 323 |
+
|
| 324 |
+
## Getting Started
|
| 325 |
+
|
| 326 |
+
### Prerequisites
|
| 327 |
+
|
| 328 |
+
- Python 3.12+
|
| 329 |
+
- vLLM running a Qwen multimodal model on ROCm, accessible at `http://localhost:8000/v1`
|
| 330 |
+
- ROCm-compatible AMD GPU (MI300X recommended)
|
| 331 |
+
|
| 332 |
+
### Installation
|
| 333 |
+
|
| 334 |
+
```bash
|
| 335 |
+
# Clone the repository
|
| 336 |
+
git clone https://github.com/Ramyar2007/mediagent
|
| 337 |
+
cd mediagent
|
| 338 |
+
|
| 339 |
+
# Install Python dependencies
|
| 340 |
+
pip install -r requirements.txt
|
| 341 |
+
|
| 342 |
+
# Configure environment
|
| 343 |
+
cp .env.example .env
|
| 344 |
+
# Edit .env and set LLM_BASE_URL to your vLLM endpoint
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
### Environment Variables
|
| 348 |
+
|
| 349 |
+
```env
|
| 350 |
+
LLM_BASE_URL=http://localhost:8000/v1 # vLLM OpenAI-compatible endpoint
|
| 351 |
+
LLM_MODEL=/model # Model path served by vLLM
|
| 352 |
+
APP_PORT=8090 # Server port
|
| 353 |
+
```
|
| 354 |
+
|
| 355 |
+
### Run
|
| 356 |
+
|
| 357 |
+
```bash
|
| 358 |
+
python main.py
|
| 359 |
+
```
|
| 360 |
+
|
| 361 |
+
Dashboard available at **http://localhost:8090**
|
| 362 |
+
|
| 363 |
+
Swagger docs at **http://localhost:8090/api/docs**
|
| 364 |
+
|
| 365 |
+
---
|
| 366 |
+
|
| 367 |
+
## Dependencies
|
| 368 |
+
|
| 369 |
+
| Package | Version | Purpose |
|
| 370 |
+
|---|---|---|
|
| 371 |
+
| `fastapi` | 0.115.6 | Web framework |
|
| 372 |
+
| `uvicorn[standard]` | 0.34.0 | ASGI server |
|
| 373 |
+
| `openai` | 1.58.1 | SDK for vLLM OpenAI-compatible API |
|
| 374 |
+
| `python-multipart` | 0.0.20 | Multipart form / file upload |
|
| 375 |
+
| `pydantic` | 2.10.5 | Data validation and serialization |
|
| 376 |
+
| `Pillow` | 11.1.0 | Image processing for DICOM conversion |
|
| 377 |
+
| `pydicom` | 2.4.4 | DICOM file parsing and metadata extraction |
|
| 378 |
+
| `numpy` | 1.26.4 | Pixel array normalization for DICOM |
|
| 379 |
+
|
| 380 |
+
Optional: `amdsmi` Python library β used automatically when available for more accurate GPU metrics than the `rocm-smi` CLI fallback.
|
| 381 |
+
|
| 382 |
+
---
|
| 383 |
+
|
| 384 |
+
## Clinical Safety
|
| 385 |
+
|
| 386 |
+
MediAgent is built with clinical safety as a first-class concern, not an afterthought.
|
| 387 |
+
|
| 388 |
+
**Mandatory disclaimer** β enforced at two independent code layers and cannot be overridden by any LLM output:
|
| 389 |
+
|
| 390 |
+
> *"This analysis is AI-generated and must be reviewed by a licensed radiologist before any clinical decisions are made."*
|
| 391 |
+
|
| 392 |
+
**Hard safety rules that run deterministically, without LLM involvement:**
|
| 393 |
+
- 16 urgent clinical keywords trigger immediate flags before any AI processing
|
| 394 |
+
- Pediatric and geriatric age thresholds auto-flag for specialist review
|
| 395 |
+
- Quality score is hard-capped at 40/100 if core agents (Vision, Report) fail
|
| 396 |
+
- Low-confidence findings are always flagged with confirmatory imaging recommendations
|
| 397 |
+
- The disclaimer is re-enforced after every LLM call, unconditionally
|
| 398 |
+
|
| 399 |
+
**This system is a decision support tool, not a clinical decision maker.** Every output is intended to assist, not replace, a licensed radiologist.
|
| 400 |
+
|
| 401 |
+
---
|
| 402 |
+
|
| 403 |
+
## Dashboard Preview
|
| 404 |
+
|
| 405 |
+
The single-page clinical dashboard provides:
|
| 406 |
+
|
| 407 |
+
- **Live pipeline panel** β real-time agent status cards with per-step runtime counters
|
| 408 |
+
- **Analytics tab** β severity distribution donut chart, differential diagnosis confidence bar chart, agent timing bar chart β all populated from structured model output
|
| 409 |
+
- **Report panel** β severity banner, safety flags, all six report sections, finding cards color-coded by severity
|
| 410 |
+
- **DICOM metadata card** β study date, institution, modality, body part, technical parameters
|
| 411 |
+
- **PDF export** β full formatted report generated client-side
|
| 412 |
+
- **Clinical chat** β slide-up Q&A panel backed by the ClinicalAdvisorAgent
|
| 413 |
+
- **AMD GPU panel** β live util %, VRAM used/total, temperature, power draw β polling every 3 seconds
|
| 414 |
+
|
| 415 |
+
---
|
| 416 |
+
|
| 417 |
+
## Built For
|
| 418 |
+
|
| 419 |
+
**AMD Developer Hackathon 2026**
|
| 420 |
+
Track: Vision & Multimodal AI
|
| 421 |
+
|
| 422 |
+
This project demonstrates that AMD's ROCm ecosystem is a complete, production-viable alternative for serious AI workloads. Medical imaging analysis β with real multimodal vision, structured clinical reasoning, and standards-compliant output β running fully on AMD MI300X without a single NVIDIA or cloud dependency.
|
| 423 |
+
|
| 424 |
+
---
|
| 425 |
+
|
| 426 |
+
<div align="center">
|
| 427 |
+
|
| 428 |
+
**Built by Ramyar Β· Sulaymaniyah, Iraq**
|
| 429 |
+
|
| 430 |
+
*#AMDDevChallenge Β· AMD Instinct MI300X Β· ROCm Β· vLLM Β· Qwen*
|
| 431 |
+
|
| 432 |
+
</div>
|