--- license: mit title: Radiology Report Generation System sdk: docker emoji: 🏢 colorFrom: blue colorTo: green --- # Radiology AI Report Generation System v2.0 AI-powered radiology report generation using BLIP-2 vision + Phi-2 LLM fine-tuned on real radiology reports. ## What it does - Upload any radiology image (X-ray, CT, MRI, Ultrasound, PET, Mammography, etc.) - BLIP-2 reads the actual image and describes what it sees - Phi-2 (fine-tuned on 227,835 real radiology reports) generates a structured report - Outputs: FINDINGS, IMPRESSION, RECOMMENDATIONS + UMLS/ICD-10/SNOMED CT codes ## Requirements - Windows 10/11 - Python 3.10 - NVIDIA GPU with 8GB+ VRAM (RTX 4060 or better) - CUDA 12.8 - 20GB free disk space (for models) --- ## Quick Start ### Step 1 — Setup (run once) ``` Double-click: setup.bat ``` This creates venv, installs all dependencies, verifies GPU. ### Step 2 — Fine-tune (run once, ~35 minutes) ``` Double-click: run_training.bat ``` Downloads unsloth/Radiology_mini (227,835 real reports) and fine-tunes Phi-2. ### Step 3 — Start the system Terminal 1: ``` run_backend.bat ``` Terminal 2: ``` run_frontend.bat ``` ### Step 4 — Use the system Open browser: http://localhost:7860 --- ## Manual commands (if .bat files don't work) ```bash cd D:\radiology_ai_system venv\Scripts\activate # Backend set USE_4BIT=true set ENABLE_VISION_CAPTION=true uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000 # Frontend (new terminal) venv\Scripts\activate python frontend/ui.py # Fine-tuning (Git Bash) python training/train_unsloth.py --max_steps 300 ``` --- ## Project Structure ``` radiology_ai_system/ ├── backend/ │ ├── main.py # FastAPI endpoints │ ├── model_loader.py # BLIP-2 + Phi-2 loading │ ├── preprocessing.py # Image preprocessing (9 modalities) │ ├── report_generator.py # Report generation + parsing │ ├── validation_module.py # Report quality scoring │ └── medical_coding.py # UMLS/ICD-10/SNOMED CT ├── frontend/ │ └── ui.py # Gradio UI ├── training/ │ ├── train_unsloth.py # Fine-tuning on Radiology_mini │ ├── prepare_dataset.py # Dataset preparation │ └── evaluate_model.py # Model evaluation ├── models/ │ ├── slm_model/ # Phi-2 cached here │ │ └── lora_adapter/ # Fine-tuned LoRA adapter saved here │ └── vision_encoder/ # BLIP-2 cached here ├── setup.bat # One-time setup ├── run_backend.bat # Start backend ├── run_frontend.bat # Start frontend ├── run_training.bat # Fine-tune model └── requirements.txt ``` --- ## VRAM Usage | Component | VRAM | |---------------|--------| | Phi-2 (4-bit) | ~2.0GB | | BLIP-2 | ~3.5GB | | Total | ~5.5GB | | Available | 8.6GB ✅ | --- ## API Endpoints - POST /api/generate-report — Generate report from image - GET /api/report/{id} — Get stored report - GET /api/export/pdf/{id} — Download PDF - GET /api/export/json/{id} — Download JSON - GET /api/health — System health - GET /docs — Swagger UI (http://localhost:8000/docs)