Upload 3 files
Browse files- README.md +109 -0
- app.py +104 -0
- requirements.txt +9 -0
README.md
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: MediSync - Multi-Modal Medical Analysis System
|
3 |
+
emoji: 🩺
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: "3.41.0"
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
+
|
14 |
+
# MediSync: Multi-Modal Medical Analysis System
|
15 |
+
|
16 |
+
MediSync is an AI-powered healthcare solution that combines X-ray image analysis with patient report text processing to provide comprehensive medical insights.
|
17 |
+
|
18 |
+
Introduction
|
19 |
+
MediSync is a multi-modal AI system that combines X-ray image analysis with medical report text processing to provide comprehensive medical insights. By leveraging state-of-the-art deep learning models for both vision and language understanding, MediSync can:
|
20 |
+
|
21 |
+
Analyze chest X-ray images to detect abnormalities
|
22 |
+
Extract key clinical information from medical reports
|
23 |
+
Fuse insights from both modalities for enhanced diagnosis support
|
24 |
+
Provide comprehensive visualization of analysis results
|
25 |
+
This AI system demonstrates the power of multi-modal fusion in the healthcare domain, where integrating information from multiple sources can lead to more robust and accurate analyses.
|
26 |
+
|
27 |
+
System Architecture
|
28 |
+
MediSync follows a modular architecture with three main components:
|
29 |
+
|
30 |
+
Image Analysis Module: Processes X-ray images using pre-trained vision models
|
31 |
+
Text Analysis Module: Analyzes medical reports using NLP models
|
32 |
+
Multimodal Fusion Module: Combines insights from both modalities
|
33 |
+
The system uses the following high-level workflow:
|
34 |
+
|
35 |
+
┌─────────────────┐
|
36 |
+
│ X-ray Image │
|
37 |
+
└────────┬────────┘
|
38 |
+
│
|
39 |
+
▼
|
40 |
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
41 |
+
│ Preprocessing │───▶│ Image Analysis │───▶│ │
|
42 |
+
└─────────────────┘ └─────────────────┘ │ │
|
43 |
+
│ Multimodal │
|
44 |
+
┌─────────────────┐ ┌─────────────────┐ │ Fusion │───▶ Results
|
45 |
+
│ Medical Report │───▶│ Text Analysis │───▶│ │
|
46 |
+
└─────────────────┘ └─────────────────┘ │ │
|
47 |
+
└─────────────────┘
|
48 |
+
|
49 |
+
|
50 |
+
## Features
|
51 |
+
|
52 |
+
- **X-ray Image Analysis**: Detects abnormalities in chest X-rays using pre-trained vision models from Hugging Face.
|
53 |
+
- **Medical Report Processing**: Extracts key information from patient reports using NLP models.
|
54 |
+
- **Multi-modal Integration**: Combines insights from both image and text data for more accurate diagnosis suggestions.
|
55 |
+
- **User-friendly Interface**: Simple web interface for uploading images and reports.
|
56 |
+
|
57 |
+
## Project Structure
|
58 |
+
|
59 |
+
```
|
60 |
+
mediSync/
|
61 |
+
├── app.py # Main application with Gradio interface
|
62 |
+
├── models/
|
63 |
+
│ ├── image_analyzer.py # X-ray image analysis module
|
64 |
+
│ ├── text_analyzer.py # Medical report text analysis module
|
65 |
+
│ └── multimodal_fusion.py # Fusion of image and text insights
|
66 |
+
├── utils/
|
67 |
+
│ ├── preprocessing.py # Data preprocessing utilities
|
68 |
+
│ └── visualization.py # Result visualization utilities
|
69 |
+
├── data/
|
70 |
+
│ └── sample/ # Sample data for testing
|
71 |
+
└── tests/ # Unit tests
|
72 |
+
```
|
73 |
+
|
74 |
+
## Setup Instructions
|
75 |
+
|
76 |
+
1. Clone this repository:
|
77 |
+
```bash
|
78 |
+
git clone [repository-url]
|
79 |
+
cd MediSync
|
80 |
+
```
|
81 |
+
|
82 |
+
2. Install dependencies:
|
83 |
+
```bash
|
84 |
+
pip install -r requirements.txt
|
85 |
+
```
|
86 |
+
|
87 |
+
3. Run the application:
|
88 |
+
```bash
|
89 |
+
python app.py
|
90 |
+
```
|
91 |
+
|
92 |
+
4. Access the web interface at `http://localhost:7860`
|
93 |
+
|
94 |
+
## Models Used
|
95 |
+
|
96 |
+
- **X-ray Analysis**: facebook/deit-base-patch16-224-medical-cxr
|
97 |
+
- **Medical Text Analysis**: medicalai/ClinicalBERT
|
98 |
+
- **Additional Support Models**: Medical question answering and entity recognition models
|
99 |
+
|
100 |
+
## Use Cases
|
101 |
+
|
102 |
+
- Preliminary screening of chest X-rays
|
103 |
+
- Cross-validation of radiologist reports
|
104 |
+
- Educational tool for medical students
|
105 |
+
- Research tool for studying correlation between visual findings and written reports
|
106 |
+
|
107 |
+
## Note
|
108 |
+
|
109 |
+
This system is designed as a support tool and should not replace professional medical diagnosis. Always consult with healthcare professionals for medical decisions.
|
app.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# Import modules
|
4 |
+
from models.image_analyzer import ImageAnalyzer
|
5 |
+
from models.multimodal_fusion import MultimodalFusion
|
6 |
+
from models.text_analyzer import TextAnalyzer
|
7 |
+
from utils.visualization import create_combined_visualization
|
8 |
+
|
9 |
+
|
10 |
+
def process_input(image, medical_report):
|
11 |
+
"""Process the image and text inputs and provide combined analysis"""
|
12 |
+
# Initialize analyzers
|
13 |
+
image_analyzer = ImageAnalyzer()
|
14 |
+
text_analyzer = TextAnalyzer()
|
15 |
+
fusion_model = MultimodalFusion()
|
16 |
+
|
17 |
+
# Analyze inputs
|
18 |
+
image_results = image_analyzer.analyze(image)
|
19 |
+
text_results = text_analyzer.analyze(medical_report)
|
20 |
+
|
21 |
+
# Fuse insights
|
22 |
+
combined_results = fusion_model.fuse_insights(image_results, text_results)
|
23 |
+
|
24 |
+
# Visualize results
|
25 |
+
visualization = create_combined_visualization(
|
26 |
+
image, image_results, text_results, combined_results
|
27 |
+
)
|
28 |
+
|
29 |
+
# Format results for display
|
30 |
+
image_findings = "\n".join(
|
31 |
+
[
|
32 |
+
f"{k}: {v:.2f}" if isinstance(v, float) else f"{k}: {v}"
|
33 |
+
for k, v in image_results.items()
|
34 |
+
]
|
35 |
+
)
|
36 |
+
text_findings = "\n".join(
|
37 |
+
[f"{k}: {v}" for k, v in text_results.items() if k != "Entities"]
|
38 |
+
)
|
39 |
+
entities = ", ".join(text_results.get("Entities", []))
|
40 |
+
|
41 |
+
recommendation = combined_results.get("Recommendation", "No recommendation")
|
42 |
+
confidence = combined_results.get("Confidence", "N/A")
|
43 |
+
|
44 |
+
return (
|
45 |
+
visualization,
|
46 |
+
image_findings,
|
47 |
+
text_findings,
|
48 |
+
entities,
|
49 |
+
recommendation,
|
50 |
+
confidence,
|
51 |
+
)
|
52 |
+
|
53 |
+
|
54 |
+
# Create Gradio interface
|
55 |
+
with gr.Blocks(title="MediSync: Multi-Modal Medical Analysis System") as demo:
|
56 |
+
gr.Markdown("# MediSync: Multi-Modal Medical Analysis System")
|
57 |
+
gr.Markdown(
|
58 |
+
"Upload a chest X-ray image and provide a medical report for comprehensive analysis"
|
59 |
+
)
|
60 |
+
|
61 |
+
with gr.Row():
|
62 |
+
with gr.Column():
|
63 |
+
image_input = gr.Image(type="pil", label="Upload X-ray Image")
|
64 |
+
text_input = gr.Textbox(lines=10, label="Enter Medical Report")
|
65 |
+
submit_btn = gr.Button("Analyze")
|
66 |
+
|
67 |
+
with gr.Column():
|
68 |
+
output_image = gr.Image(type="pil", label="Visualization")
|
69 |
+
|
70 |
+
with gr.Tab("Summary"):
|
71 |
+
recommendation_output = gr.Textbox(label="Recommendation")
|
72 |
+
confidence_output = gr.Textbox(label="Confidence Score")
|
73 |
+
|
74 |
+
with gr.Tab("Detailed Results"):
|
75 |
+
image_output = gr.Textbox(label="Image Analysis")
|
76 |
+
text_output = gr.Textbox(label="Text Analysis")
|
77 |
+
entities_output = gr.Textbox(label="Detected Medical Entities")
|
78 |
+
|
79 |
+
submit_btn.click(
|
80 |
+
process_input,
|
81 |
+
inputs=[image_input, text_input],
|
82 |
+
outputs=[
|
83 |
+
output_image,
|
84 |
+
image_output,
|
85 |
+
text_output,
|
86 |
+
entities_output,
|
87 |
+
recommendation_output,
|
88 |
+
confidence_output,
|
89 |
+
],
|
90 |
+
)
|
91 |
+
|
92 |
+
gr.Markdown("""
|
93 |
+
## About MediSync
|
94 |
+
|
95 |
+
MediSync is an AI-powered healthcare solution that combines X-ray image analysis with patient report text processing
|
96 |
+
to provide comprehensive medical insights.
|
97 |
+
|
98 |
+
**Note:** This system is designed as a support tool and should not replace professional medical diagnosis.
|
99 |
+
Always consult with healthcare professionals for medical decisions.
|
100 |
+
""")
|
101 |
+
|
102 |
+
# Launch the app
|
103 |
+
if __name__ == "__main__":
|
104 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.41.0
|
2 |
+
torch>=1.10.0
|
3 |
+
transformers>=4.20.0
|
4 |
+
Pillow>=9.0.0
|
5 |
+
numpy>=1.20.0
|
6 |
+
sentencepiece>=0.1.96
|
7 |
+
protobuf>=3.19.0
|
8 |
+
accelerate>=0.15.0
|
9 |
+
matplotlib>=3.5.0
|