Spaces:
Runtime error
Runtime error
File size: 3,312 Bytes
12e3308 2306d9c 2bbf49a 2306d9c 2bbf49a 2306d9c 12e3308 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | ---
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) |