This application uses fine-tuned Large Language Models to generate detailed radiology reports from chest X-ray images. It provides a user-friendly interface for healthcare professionals to upload X-ray images and receive professionally formatted radiology reports with findings and impressions.
- Multiple Model Support: Choose from different fine-tuned LLMs (Llama, Qwen, Phi, GPT, Zephyr)
- Professional Report Format: Automatically structures reports with FINDINGS and IMPRESSION sections
- User-Friendly Interface: Clean, intuitive Streamlit web interface
- Report Download: Download generated reports as text files
- Debug Mode: Optional debug features for development and troubleshooting
- Frontend: Streamlit
- Backend: PyTorch, Transformers, Lightning
- Models:
- Vision Transformer (Swin Tiny) for image encoding
- Various LLMs for text generation (Llama-3.2-3B, Qwen2-1.5B, Phi-2, Cerebras-GPT-1.3B, StableLM-Zephyr-3B)
- Deployment: Ngrok for tunneling
Requirements are listed in requirements.txt. The main dependencies include:
- streamlit
- torch
- transformers
- lightning
- pyngrok
- matplotlib
- pillow
-
download the file
download project_user_interface.ipynb
-
Install dependencies
pip install -r requirements.txt
-
Run the application
streamlit run app.py
- Upload the notebook to Google Colab
- Run the cells to install dependencies
- Set up Hugging Face access token if needed
- Run the Streamlit app with Ngrok for public access
The application uses a two-stage approach:
- Image Encoding: X-ray images are processed through a vision transformer to extract visual features
- Report Generation: The visual features are fed into a fine-tuned LLM with a specialized prompt to generate the radiology report
The R2GenGPT class integrates these components, providing a seamless pipeline from image to report.
radiology-report-generator/
├── app.py # Main Streamlit application
├── models/ # Directory for model checkpoints
│ ├── llama-3.2-3b/
│ ├── qwen2-1.5b/
│ ├── phi-2/
│ ├── gpt-1.3b/
│ └── stablelm-zephyr-3b/
├── requirements.txt # Python dependencies
└── README.md # Project documentation
- Start the application
- Select a model from the dropdown menu
- Upload a chest X-ray image (JPG, JPEG, or PNG)
- Click "Generate Report"
- View the generated report in the right panel
- Download the report as a text file if needed
The application includes a debug mode that provides additional information for development:
- Raw model output
- Processed report text
- Tokenizer information
- Error logs
Enable debug mode by checking the "Debug Mode" checkbox in the sidebar.
The application includes multiple fallback mechanisms to ensure reliability:
- Alternative generation parameters if the primary approach fails
- Post-processing to ensure proper report formatting
- Default report templates for error cases
MIT License 1.0
If you use this project in your research, please cite:
@software{radiology_report_generator,
author = {Amirparsa Rouhi},
title = {Radiology Report Generator},
year = {2025},
url = {https://github.com/ai-art-dev99/xray-report-generation}
}
- Hugging Face for model repositories
- PyTorch and Lightning for deep learning frameworks
- Streamlit for the web interface