Diabetic retinopathy screening prototype built with FastAPI. The project combines retinal image analysis, segmentation, and LLM-based report generation to produce interpretable outputs for screening workflows.
- FastAPI backend with vision and NLP endpoints
- Retina image segmentation pipeline for vessel and lesion analysis
- Prompt/template layer for generating structured reports
- Notebooks for experimentation, training, and evaluation
DRP_segmentation/
├── notebooks/ # Exploration, training, and evaluation notebooks
├── src/
│ ├── main.py # FastAPI app entry point
│ ├── routes/ # API routes for vision and NLP
│ ├── controllers/ # Application logic
│ ├── engine/ # Image preprocessing and segmentation
│ ├── llm/ # LLM provider and template utilities
│ ├── helpers/ # Settings and shared helpers
│ ├── models/ # Enums and model-related assets
│ └── requirements.txt # App-specific dependencies
├── requirements.txt # Root dependencies for the app
├── Dockerfile # Containerized runtime
└── README.md
- Analyze a retinal image and return an overlay plus a generated report
- Generate structured NLP outputs from model results
- Load segmentation weights at startup for vessel and lesion inference
- Support configurable LLM providers through environment settings
- Python 3.10+
- A valid Cohere API key if you want to use the LLM-backed report generation
- Trained model weights placed at the paths expected by
src/main.py
pip install -r requirements.txt
If you are running the application from inside src/, install the dependencies from src/requirements.txt instead.
The application reads settings from a .env file through Pydantic settings. At minimum, provide:
APP_NAME=DRP Segmentation APP_VERSION=1.0.0 GENERATION_BACKEND=cohere COHERE_API_KEY=your_api_key_here GENERATION_MODEL_ID=your_model_id_here
Optional tuning values:
INPUT_DAFAULT_MAX_CHARACTERS=2000 GENERATION_DAFAULT_MAX_TOKENS=2000 GENERATION_DAFAULT_TEMPERATURE=0.1 ORGINAL_LANGUGE=ar DEFAULT_LANGUGE=ar
The Docker image starts the service with Uvicorn on port 7860.
uvicorn src.main:app --host 0.0.0.0 --port 7860
Upload a retinal image and receive:
original_imageoverlay_imagereportfull_prompt
The endpoint rejects non-image uploads.
Generates a structured report from sample model results using the configured LLM provider.
The notebooks in notebooks/ are still useful for experimentation and evaluation, but they are no longer the primary way to run the project.
01_disease_segmentation.ipynb- DR grading and preprocessing02_vessel_segmentation.ipynb- vessel segmentation experiments03_binary_classification_filter.ipynb- binary DR filtering04_dr_grading_model.ipynb- grading model work05_evaluation.ipynb- evaluation experiments06_gradcam_pipeline.ipynb- explainability pipeline
- Keep raw datasets outside version control
- Store processed artifacts separately from source code
- Place the trained weights where
src/main.pyexpects them before starting the API
- The codebase currently mixes API, prompting, and inference concerns, so the README now focuses on how to run and use the service.
- Several notebook workflows are still useful, but they are historical support material rather than the main entry point.