--- 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 **MedGemma Models (Automatic):** - Models download automatically from Hugging Face Hub on first use - No manual installation required - Choose between 4B (faster) or 27B (more accurate) models **RF-DETR Model (Your Custom Model):** You have two options for uploading your custom RF-DETR model: ### Option 1: Direct Upload (Simple) 1. Upload your `rf-detr-medium.pth` file directly to your Space 2. The app will automatically find and use it ### Option 2: Model Repository (Recommended) 1. Create a separate Hugging Face model repository (e.g., `your-username/rf-detr-medical`) 2. Upload your model files there 3. Set the environment variable `RFDETR_HF_REPO` to your repository ID **To set the environment variable:** - Go to your Space settings - Add `RFDETR_HF_REPO` with your model repository ID (e.g., `your-username/rf-detr-medical`) - The app will download from your repository automatically ## 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.