Dhruv-Ty commited on
Commit
35888e1
·
1 Parent(s): cb3a670

readme updated

Browse files
Files changed (1) hide show
  1. README.md +10 -266
README.md CHANGED
@@ -1,267 +1,11 @@
1
- <h1 align="center">
2
- 🤖 MedRAX: Medical Reasoning Agent for Chest X-ray
3
- </h1>
4
- <p align="center"> <a href="https://arxiv.org/abs/2502.02673" target="_blank"><img src="https://img.shields.io/badge/arXiv-Paper-FF6B6B?style=for-the-badge&logo=arxiv&logoColor=white" alt="arXiv"></a> <a href="https://github.com/bowang-lab/MedRAX"><img src="https://img.shields.io/badge/GitHub-Code-4A90E2?style=for-the-badge&logo=github&logoColor=white" alt="GitHub"></a> <a href="https://huggingface.co/datasets/wanglab/chest-agent-bench"><img src="https://img.shields.io/badge/HuggingFace-Dataset-FFBF00?style=for-the-badge&logo=huggingface&logoColor=white" alt="HuggingFace Dataset"></a> </p>
5
-
6
- ![](assets/demo_fast.gif?autoplay=1)
7
-
8
- <br>
9
-
10
- ## Abstract
11
- Chest X-rays (CXRs) play an integral role in driving critical decisions in disease management and patient care. While recent innovations have led to specialized models for various CXR interpretation tasks, these solutions often operate in isolation, limiting their practical utility in clinical practice. We present MedRAX, the first versatile AI agent that seamlessly integrates state-of-the-art CXR analysis tools and multimodal large language models into a unified framework. MedRAX dynamically leverages these models to address complex medical queries without requiring additional training. To rigorously evaluate its capabilities, we introduce ChestAgentBench, a comprehensive benchmark containing 2,500 complex medical queries across 7 diverse categories. Our experiments demonstrate that MedRAX achieves state-of-the-art performance compared to both open-source and proprietary models, representing a significant step toward the practical deployment of automated CXR interpretation systems.
12
- <br><br>
13
-
14
-
15
- ## MedRAX
16
- MedRAX is built on a robust technical foundation:
17
- - **Core Architecture**: Built on LangChain and LangGraph frameworks
18
- - **Language Model**: Uses GPT-4o with vision capabilities as the backbone LLM
19
- - **Deployment**: Supports both local and cloud-based deployments
20
- - **Interface**: Production-ready interface built with Gradio
21
- - **Modular Design**: Tool-agnostic architecture allowing easy integration of new capabilities
22
-
23
- ### Integrated Tools
24
- - **Visual QA**: Utilizes CheXagent and LLaVA-Med for complex visual understanding and medical reasoning
25
- - **Segmentation**: Employs MedSAM and PSPNet model trained on ChestX-Det for precise anatomical structure identification
26
- - **Grounding**: Uses Maira-2 for localizing specific findings in medical images
27
- - **Report Generation**: Implements SwinV2 Transformer trained on CheXpert Plus for detailed medical reporting
28
- - **Disease Classification**: Leverages DenseNet-121 from TorchXRayVision for detecting 18 pathology classes
29
- - **X-ray Generation**: Utilizes RoentGen for synthetic CXR generation
30
- - **Utilities**: Includes DICOM processing, visualization tools, and custom plotting capabilities
31
-
32
- Note the current version of MedRAX is experimentally released and does not support vision for GPT-4o and MedSAM. We will be integrating these shortly.
33
- <br><br>
34
-
35
-
36
- ## ChestAgentBench
37
- We introduce ChestAgentBench, a comprehensive evaluation framework with 2,500 complex medical queries across 7 categories, built from 675 expert-curated clinical cases. The benchmark evaluates complex multi-step reasoning in CXR interpretation through:
38
-
39
- - Detection
40
- - Classification
41
- - Localization
42
- - Comparison
43
- - Relationship
44
- - Diagnosis
45
- - Characterization
46
-
47
- Download the benchmark: [ChestAgentBench on Hugging Face](https://huggingface.co/datasets/wanglab/chest-agent-bench)
48
- ```
49
- huggingface-cli download wanglab/chestagentbench --repo-type dataset --local-dir chestagentbench
50
- ```
51
-
52
- Unzip the Eurorad figures to your local `MedMAX` directory.
53
- ```
54
- unzip chestagentbench/figures.zip
55
- ```
56
-
57
- To evaluate with GPT-4o, set your OpenAI API key and run the quickstart script.
58
- ```
59
- export OPENAI_API_KEY="<your-openai-api-key>"
60
- python quickstart.py \
61
- --model chatgpt-4o-latest \
62
- --temperature 0.2 \
63
- --max-cases 2 \
64
- --log-prefix chatgpt-4o-latest \
65
- --use-urls
66
- ```
67
-
68
-
69
- <br>
70
-
71
- ## Installation
72
- ### Prerequisites
73
- - Python 3.8+
74
- - CUDA/GPU for best performance
75
-
76
- ### Installation Steps
77
- ```bash
78
- # Clone the repository
79
- git clone https://github.com/bowang-lab/MedRAX.git
80
- cd MedRAX
81
-
82
- # Install package
83
- pip install -e .
84
- ```
85
-
86
- ### Getting Started
87
- ```bash
88
- # Start the Gradio interface
89
- python main.py
90
- ```
91
- or if you run into permission issues
92
- ```bash
93
- sudo -E env "PATH=$PATH" python main.py
94
- ```
95
- You need to setup the `model_dir` inside `main.py` to the directory where you want to download or already have the weights of above tools from Hugging Face.
96
- Comment out the tools that you do not have access to.
97
- Make sure to setup your OpenAI API key in `.env` file!
98
- <br><br><br>
99
-
100
-
101
- ## Tool Selection and Initialization
102
-
103
- MedRAX supports selective tool initialization, allowing you to use only the tools you need. Tools can be specified when initializing the agent (look at `main.py`):
104
-
105
- ```python
106
- selected_tools = [
107
- "ImageVisualizerTool",
108
- "ChestXRayClassifierTool",
109
- "ChestXRaySegmentationTool",
110
- # Add or remove tools as needed
111
- ]
112
-
113
- agent, tools_dict = initialize_agent(
114
- "medrax/docs/system_prompts.txt",
115
- tools_to_use=selected_tools,
116
- model_dir="/model-weights"
117
- )
118
- ```
119
-
120
- <br><br>
121
- ## Automatically Downloaded Models
122
-
123
- The following tools will automatically download their model weights when initialized:
124
-
125
- ### Classification Tool
126
- ```python
127
- ChestXRayClassifierTool(device=device)
128
- ```
129
-
130
- ### Segmentation Tool
131
- ```python
132
- ChestXRaySegmentationTool(device=device)
133
- ```
134
-
135
- ### Grounding Tool
136
- ```python
137
- XRayPhraseGroundingTool(
138
- cache_dir=model_dir,
139
- temp_dir=temp_dir,
140
- load_in_8bit=True,
141
- device=device
142
- )
143
- ```
144
- - Maira-2 weights download to specified `cache_dir`
145
- - 8-bit and 4-bit quantization available for reduced memory usage
146
-
147
- ### LLaVA-Med Tool
148
- ```python
149
- LlavaMedTool(
150
- cache_dir=model_dir,
151
- device=device,
152
- load_in_8bit=True
153
- )
154
- ```
155
- - Automatic weight download to `cache_dir`
156
- - 8-bit and 4-bit quantization available for reduced memory usage
157
-
158
- ### Report Generation Tool
159
- ```python
160
- ChestXRayReportGeneratorTool(
161
- cache_dir=model_dir,
162
- device=device
163
- )
164
- ```
165
-
166
- ### Visual QA Tool
167
- ```python
168
- XRayVQATool(
169
- cache_dir=model_dir,
170
- device=device
171
- )
172
- ```
173
- - CheXagent weights download automatically
174
-
175
- ### MedSAM Tool
176
- ```
177
- Support for MedSAM segmentation will be added in a future update.
178
- ```
179
-
180
- ### Utility Tools
181
- No additional model weights required:
182
- ```python
183
- ImageVisualizerTool()
184
- DicomProcessorTool(temp_dir=temp_dir)
185
- ```
186
- <br>
187
-
188
- ## Manual Setup Required
189
-
190
- ### Image Generation Tool
191
- ```python
192
- ChestXRayGeneratorTool(
193
- model_path=f"{model_dir}/roentgen",
194
- temp_dir=temp_dir,
195
- device=device
196
- )
197
- ```
198
- - RoentGen weights require manual setup:
199
- 1. Contact authors: https://github.com/StanfordMIMI/RoentGen
200
- 2. Place weights in `{model_dir}/roentgen`
201
- 3. Optional tool, can be excluded if not needed
202
- <br>
203
-
204
- ## Configuration Notes
205
-
206
- ### Required Parameters
207
- - `model_dir` or `cache_dir`: Base directory for model weights that Hugging Face uses
208
- - `temp_dir`: Directory for temporary files
209
- - `device`: "cuda" for GPU, "cpu" for CPU-only
210
-
211
- ### Memory Management
212
- - Consider selective tool initialization for resource constraints
213
- - Use 8-bit quantization where available
214
- - Some tools (LLaVA-Med, Grounding) are more resource-intensive
215
- <br>
216
-
217
- ### Local LLMs
218
- If you are running a local LLM using frameworks like [Ollama](https://ollama.com/) or [LM Studio](https://lmstudio.ai/), you need to configure your environment variables accordingly. For example:
219
- ```
220
- export OPENAI_BASE_URL="http://localhost:11434/v1"
221
- export OPENAI_API_KEY="ollama"
222
- ```
223
- <br>
224
-
225
- ## Star History
226
- <div align="center">
227
-
228
- [![Star History Chart](https://api.star-history.com/svg?repos=bowang-lab/MedRAX&type=Date)](https://star-history.com/#bowang-lab/MedRAX&Date)
229
-
230
- </div>
231
- <br>
232
-
233
-
234
- ## Authors
235
- - **Adibvafa Fallahpour**¹²³ * ([email protected])
236
- - **Jun Ma**²³ *
237
- - **Alif Munim**³⁴ *
238
- - **Hongwei Lyu**³
239
- - **Bo Wang**¹²³⁵
240
-
241
- ¹ Department of Computer Science, University of Toronto, Toronto, Canada
242
- ² Vector Institute, Toronto, Canada
243
- ³ University Health Network, Toronto, Canada
244
- ⁴ Cohere For AI, Toronto, Canada
245
- ⁵ Department of Laboratory Medicine and Pathobiology, University of Toronto, Toronto, Canada <br>
246
- \* Equal contribution
247
- <br><br>
248
-
249
-
250
- ## Citation
251
- If you find this work useful, please cite our paper:
252
- ```bibtex
253
- @misc{fallahpour2025medraxmedicalreasoningagent,
254
- title={MedRAX: Medical Reasoning Agent for Chest X-ray},
255
- author={Adibvafa Fallahpour and Jun Ma and Alif Munim and Hongwei Lyu and Bo Wang},
256
- year={2025},
257
- eprint={2502.02673},
258
- archivePrefix={arXiv},
259
- primaryClass={cs.LG},
260
- url={https://arxiv.org/abs/2502.02673},
261
- }
262
- ```
263
-
264
  ---
265
- <p align="center">
266
- Made with ❤️ at University of Toronto, Vector Institute, and University Health Network
267
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: CRAX
3
+ emoji: 🐢
4
+ colorFrom: pink
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 5.25.2
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference