|
|
---
|
|
|
title: Medical Image Analysis Tool
|
|
|
emoji: π₯
|
|
|
colorFrom: blue
|
|
|
colorTo: green
|
|
|
sdk: gradio
|
|
|
sdk_version: "5.49.1"
|
|
|
app_file: app.py
|
|
|
pinned: false
|
|
|
license: mit
|
|
|
---
|
|
|
|
|
|
# π₯ Medical Image Analysis Tool
|
|
|
|
|
|
An AI-powered medical image analysis application using advanced detection models and large language models for medical image interpretation.
|
|
|
|
|
|
## Features
|
|
|
|
|
|
- **Advanced Object Detection**: Uses RF-DETR (Real-time Fine-grained Detection Transformer) for precise object detection
|
|
|
- **Medical AI Analysis**: Integrates MedGemma, a specialized medical vision-language model
|
|
|
- **Interactive Interface**: Built with Gradio for easy web-based interaction
|
|
|
- **Configurable Thresholds**: Adjustable confidence thresholds for detection sensitivity
|
|
|
- **Model Size Selection**: Choose between MedGemma 4B (faster) or 27B (more accurate) models
|
|
|
- **GPU Acceleration**: Optimized for GPU usage when available with 4-bit quantization
|
|
|
- **Automatic Model Downloads**: Models download automatically from Hugging Face Hub
|
|
|
|
|
|
## Models Used
|
|
|
|
|
|
- **RF-DETR Medium**: State-of-the-art object detection model
|
|
|
- **MedGemma 4B/27B**: Medical-specialized vision-language models for analysis and descriptions
|
|
|
- 4B model: Faster inference, lower memory usage
|
|
|
- 27B model: Higher accuracy, requires more resources
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
1. **Upload Image**: Click on the image upload area or drag and drop a medical image
|
|
|
2. **Adjust Settings**:
|
|
|
- Use the confidence threshold slider to control detection sensitivity
|
|
|
- Select model size (4B for speed, 27B for accuracy)
|
|
|
3. **Analyze**: Click "Analyze Image" to run the AI analysis
|
|
|
4. **View Results**: See the annotated image with detected objects and AI-generated descriptions
|
|
|
|
|
|
## Installation & Setup
|
|
|
|
|
|
This application is designed to run on Hugging Face Spaces. The following files are required:
|
|
|
|
|
|
- `app.py` - Main application file (optimized for Spaces)
|
|
|
- `requirements.txt` - Python dependencies
|
|
|
- `packages.txt` - System packages
|
|
|
- `README.md` - This documentation
|
|
|
|
|
|
## Model Loading
|
|
|
|
|
|
### π Required: Hugging Face Token (for MedGemma)
|
|
|
|
|
|
**MedGemma is a gated model**. To use AI-powered text analysis, you must:
|
|
|
|
|
|
1. Go to your **Space Settings** β **Repository secrets**
|
|
|
2. Add a new secret:
|
|
|
- **Name**: `HF_TOKEN`
|
|
|
- **Value**: Your Hugging Face token (get it from https://huggingface.co/settings/tokens)
|
|
|
3. **Important**: Accept the model license at https://huggingface.co/google/medgemma-4b-it
|
|
|
4. Save and restart your Space
|
|
|
|
|
|
**Without the token:** Object detection will still work, but AI text analysis will be disabled.
|
|
|
|
|
|
---
|
|
|
|
|
|
**MedGemma Models (Automatic):**
|
|
|
- Models download automatically from Hugging Face Hub on first use (with valid token)
|
|
|
- Uses MedGemma 4B for efficient AI-powered analysis
|
|
|
- 4-bit quantization for reduced memory usage
|
|
|
|
|
|
**RF-DETR Model (Automatic from HF Model Repo):**
|
|
|
- Model automatically downloads from `edeler/lorai` on Hugging Face
|
|
|
- No manual upload needed - configured in the app
|
|
|
- Cached locally after first download for faster subsequent runs
|
|
|
- Model file: `lorai.pth` (135MB)
|
|
|
|
|
|
## Space Configuration
|
|
|
|
|
|
For optimal performance, configure your Space settings:
|
|
|
- **Hardware**: GPU (T4 minimum, A100 recommended for 27B models)
|
|
|
- **Storage**: Enable persistent storage for model caching
|
|
|
- **Timeout**: 30+ minutes for large model downloads
|
|
|
|
|
|
## Technical Details
|
|
|
|
|
|
- **Framework**: PyTorch + Transformers
|
|
|
- **Interface**: Gradio
|
|
|
- **Computer Vision**: OpenCV, PIL, Supervision
|
|
|
- **Hardware**: Optimized for both CPU and GPU inference
|
|
|
|
|
|
## Performance Tips
|
|
|
|
|
|
- **Model Selection**: Use MedGemma 4B for faster processing or 27B for higher accuracy
|
|
|
- **Confidence Thresholds**: Higher values reduce false positives but may miss subtle findings
|
|
|
- **GPU Acceleration**: The application automatically uses GPU acceleration when available
|
|
|
- **Memory Optimization**: Uses 4-bit quantization to reduce memory usage
|
|
|
- **Model Caching**: Models are cached after first load for faster subsequent analyses
|
|
|
|
|
|
## Limitations
|
|
|
|
|
|
- Requires significant computational resources for optimal performance
|
|
|
- Best suited for medical imaging applications
|
|
|
- Results should be verified by qualified medical professionals
|
|
|
|
|
|
## Development
|
|
|
|
|
|
To run locally:
|
|
|
|
|
|
```bash
|
|
|
pip install -r requirements.txt
|
|
|
python app.py
|
|
|
```
|
|
|
|
|
|
**Note**: For local development, you'll need to:
|
|
|
1. Install the RF-DETR package or ensure it's available
|
|
|
2. Place your `rf-detr-medium.pth` file in the project directory
|
|
|
3. Models will download automatically on first run
|
|
|
|
|
|
## License
|
|
|
|
|
|
This project is for research and educational purposes. Medical applications should be developed and validated according to appropriate regulatory standards.
|
|
|
|
|
|
## Support
|
|
|
|
|
|
For issues or questions, please refer to the Hugging Face Space documentation or create an issue in the project repository.
|
|
|
=======
|
|
|
---
|
|
|
title: Medical Image Analysis Tool
|
|
|
emoji: π₯
|
|
|
colorFrom: blue
|
|
|
colorTo: green
|
|
|
sdk: gradio
|
|
|
sdk_version: 5.49.1
|
|
|
app_file: app.py
|
|
|
pinned: false
|
|
|
license: mit
|
|
|
---
|
|
|
|
|
|
# π₯ Medical Image Analysis Tool
|
|
|
|
|
|
An AI-powered medical image analysis application using advanced detection models and large language models for medical image interpretation.
|
|
|
|
|
|
## Features
|
|
|
|
|
|
- **Advanced Object Detection**: Uses RF-DETR (Real-time Fine-grained Detection Transformer) for precise object detection
|
|
|
- **Medical AI Analysis**: Integrates MedGemma, a specialized medical vision-language model
|
|
|
- **Interactive Interface**: Built with Gradio for easy web-based interaction
|
|
|
- **Configurable Thresholds**: Adjustable confidence thresholds for detection sensitivity
|
|
|
- **Model Size Selection**: Choose between MedGemma 4B (faster) or 27B (more accurate) models
|
|
|
- **GPU Acceleration**: Optimized for GPU usage when available with 4-bit quantization
|
|
|
- **Automatic Model Downloads**: Models download automatically from Hugging Face Hub
|
|
|
|
|
|
## Models Used
|
|
|
|
|
|
- **RF-DETR Medium**: State-of-the-art object detection model
|
|
|
- **MedGemma 4B/27B**: Medical-specialized vision-language models for analysis and descriptions
|
|
|
- 4B model: Faster inference, lower memory usage
|
|
|
- 27B model: Higher accuracy, requires more resources
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
1. **Upload Image**: Click on the image upload area or drag and drop a medical image
|
|
|
2. **Adjust Settings**:
|
|
|
- Use the confidence threshold slider to control detection sensitivity
|
|
|
- Select model size (4B for speed, 27B for accuracy)
|
|
|
3. **Analyze**: Click "Analyze Image" to run the AI analysis
|
|
|
4. **View Results**: See the annotated image with detected objects and AI-generated descriptions
|
|
|
|
|
|
## Installation & Setup
|
|
|
|
|
|
This application is designed to run on Hugging Face Spaces. The following files are required:
|
|
|
|
|
|
- `app.py` - Main application file (optimized for Spaces)
|
|
|
- `requirements.txt` - Python dependencies
|
|
|
- `packages.txt` - System packages
|
|
|
- `README.md` - This documentation
|
|
|
|
|
|
## Model Loading
|
|
|
|
|
|
**RF-DETR Model:**
|
|
|
- Upload your trained `rf-detr-medium.pth` file to the Space
|
|
|
- The application will automatically find and load it
|
|
|
|
|
|
**MedGemma Models:**
|
|
|
- Models download automatically from Hugging Face Hub on first use
|
|
|
- No manual installation required
|
|
|
- Choose between 4B (faster) or 27B (more accurate) models
|
|
|
|
|
|
## Space Configuration
|
|
|
|
|
|
For optimal performance, configure your Space settings:
|
|
|
- **Hardware**: GPU (T4 minimum, A100 recommended for 27B models)
|
|
|
- **Storage**: Enable persistent storage for model caching
|
|
|
- **Timeout**: 30+ minutes for large model downloads
|
|
|
|
|
|
## Technical Details
|
|
|
|
|
|
- **Framework**: PyTorch + Transformers
|
|
|
- **Interface**: Gradio
|
|
|
- **Computer Vision**: OpenCV, PIL, Supervision
|
|
|
- **Hardware**: Optimized for both CPU and GPU inference
|
|
|
|
|
|
## Performance Tips
|
|
|
|
|
|
- **Model Selection**: Use MedGemma 4B for faster processing or 27B for higher accuracy
|
|
|
- **Confidence Thresholds**: Higher values reduce false positives but may miss subtle findings
|
|
|
- **GPU Acceleration**: The application automatically uses GPU acceleration when available
|
|
|
- **Memory Optimization**: Uses 4-bit quantization to reduce memory usage
|
|
|
- **Model Caching**: Models are cached after first load for faster subsequent analyses
|
|
|
|
|
|
## Limitations
|
|
|
|
|
|
- Requires significant computational resources for optimal performance
|
|
|
- Best suited for medical imaging applications
|
|
|
- Results should be verified by qualified medical professionals
|
|
|
|
|
|
## Development
|
|
|
|
|
|
To run locally:
|
|
|
|
|
|
```bash
|
|
|
pip install -r requirements.txt
|
|
|
python app.py
|
|
|
```
|
|
|
|
|
|
**Note**: For local development, you'll need to:
|
|
|
1. Install the RF-DETR package or ensure it's available
|
|
|
2. Place your `rf-detr-medium.pth` file in the project directory
|
|
|
3. Models will download automatically on first run
|
|
|
|
|
|
## License
|
|
|
|
|
|
This project is for research and educational purposes. Medical applications should be developed and validated according to appropriate regulatory standards.
|
|
|
|
|
|
## Support
|
|
|
|
|
|
For issues or questions, please refer to the Hugging Face Space documentation or create an issue in the project repository.
|
|
|
|