---
title: EchoLens 2.0
emoji: ๐
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 5.34.2
app_file: app.py
pinned: true
license: apache-2.0
short_description: Image to Caption
---
# ๐๏ธ EchoLens 2.0 โ Realtime Vision Assistant for Blind & Low-Vision Users
[](https://lovnishverma-imagecaptioningai.hf.space/)
[](https://opensource.org/licenses/Apache-2.0)
[](https://gradio.app)
[](https://huggingface.co/microsoft/Florence-2-base)
**EchoLens** is an accessible, real-time vision assistant that helps blind and low-vision users understand their surroundings through AI-powered image captioning and text-to-speech. Point a webcam at the world, and EchoLens describes what it sees โ out loud.
---
## โจ Features
- **๐ฏ Instant scene description** โ Press `D` or click *Describe Now* to hear what the camera sees
- **๐ Realtime mode** โ Auto-describes the scene every 3.5 seconds; skips unchanged frames using perceptual hashing (dHash)
- **๐ง 5 vision tasks** โ Quick Caption, Describe Scene, Detailed Description, OCR (text reading), and Object Detection with spatial positions (left / center / right)
- **๐ฃ๏ธ Natural-sounding TTS** โ Powered by Microsoft Edge TTS with 5 voice options across US and UK accents
- **๐ Image upload support** โ Upload a photo from disk for immediate description
- **๐ Repeat last description** โ Press `P` to replay the last audio at any time
- **โฟ Accessible UI** โ Font size controls (A / A+ / A++), high-contrast toggle, full keyboard shortcuts, and ARIA live regions for screen-reader compatibility
- **๐ Session statistics** โ Track manual describes, realtime captures, and history
- **โก Smart scene-change detection** โ Only re-describes when the scene actually changes, saving compute and reducing audio fatigue
- **๐ฅ๏ธ GPU & CPU support** โ Auto-detects CUDA, MPS (Apple Silicon), or CPU; optimized dtype per device
---
## ๐น Keyboard Shortcuts
| Key | Action |
|-----|--------|
| `D` | Describe what the camera sees right now |
| `R` | Toggle realtime auto-description on/off |
| `P` | Repeat the last description |
| `Esc` | Stop all audio and exit realtime mode |
> Shortcuts work globally โ no need to focus any UI element first. They are disabled while typing in text fields.
---
## ๐ง Vision Tasks
| Task | Token | Description |
|------|-------|-------------|
| **Quick Caption** | `
` | Short one-line summary of the scene |
| **Describe Scene** | `` | Detailed multi-sentence description |
| **Detailed Description** | `` | Thorough paragraph-length description |
| **Read Text (OCR)** | `` | Reads any text visible in the image (signs, labels, screens) |
| **Detect Objects** | `` | Lists detected objects and their spatial positions |
### Object Detection Output Example
> *"I see person in the center, cup on the right, laptop on the left, and book on the left."*
The spatial positions (left / center / right) are computed from Florence-2's bounding-box coordinates, giving users a sense of *where* things are, not just *what* things are.
---
## ๐ฃ๏ธ Available Voices
| Voice | Locale | Gender |
|-------|--------|--------|
| Aria โ Female, US | `en-US` | Female |
| Guy โ Male, US | `en-US` | Male |
| Jenny โ Female, US | `en-US` | Female |
| Sonia โ Female, UK | `en-GB` | Female |
| Ryan โ Male, UK | `en-GB` | Male |
---
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Webcam Feed โโโโโโ โ
โ Image Upload โโโโโผโโโบ Preprocess (resize, enhance) โ
โโโโโโโโโโโโโโโโโโโโโโ โ โ
โผ โ
โโโโโโโโโโโโโโโโโโโโ โ
โ dHash Check โโโโโโโโโโโโโโโโค
โ (scene change?) โ โ
โโโโโโโโโโฌโโโโโโโโโโ โ
โ โ
unchanged โโโโโโ โ
changed โโโโโโโโบ Florence-2-base โ
(Microsoft) โ
โโ โ
โโ โ
โโ
โโ โ
โโ โโโบ spatial โ
formatter โ
โ
โ โ
โผ โ
โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Edge TTS (async) โ โ
โ dedicated thread โ โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โ
โผ โ
โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Gradio Audio โ โ
โ (autoplay) โ โ
โโโโโโโโโโโโโโโโโโโโโโโโ โ
```
**Scene-change detection** uses dHash (difference hash) with a configurable Hamming-distance threshold (`SCENE_THRESHOLD = 0.12`). If the new frame is โฅ88% similar to the previous one, the inference is skipped โ reducing unnecessary compute and audio fatigue.
**Dedicated TTS event loop** โ Edge-TTS runs on its own asyncio event loop in a background thread, so speech generation never blocks the vision model or the UI.
---
## ๐ Getting Started
### Run on Hugging Face Spaces
1. Click **"Duplicate this Space"** (top-right on the Hugging Face page)
2. Set visibility to **Public** or **Private**
3. Wait for the build (~2โ3 minutes on first launch)
4. Open the app โ no installation needed!
### Run locally
```bash
# 1. Clone
# git clone
cd echolens
# 2. Install dependencies
pip install -r requirements.txt
# 3. Launch
python app.py
```
The app will be available at `http://localhost:7860`.
> **Note:** The first launch downloads the Florence-2-base model (~460 MB) and performs a background warmup inference. Expect a short delay before the first description.
---
## ๐ฆ Requirements
```
transformers==4.48.0
timm
torch>=2.1.0
torchvision
Pillow>=10.0.0
einops
edge-tts
gradio==5.34.2
numpy
accelerate
```
GPU (CUDA) is used automatically if available; the app falls back to CPU otherwise. On Apple Silicon, MPS is used.
---
## โ๏ธ Configuration
All tunable constants live in the `Config` class at the top of `app.py`:
| Constant | Default | Description |
|----------|---------|-------------|
| `CAPTURE_INTERVAL` | `3.5` | Seconds between realtime captures |
| `SCENE_THRESHOLD` | `0.12` | dHash distance below which a scene is treated as unchanged |
| `MAX_DIM` | `768` | Max image dimension before inference (larger images are downscaled) |
| `TTS_RATE` | `+8%` | Speech speed adjustment for Edge TTS |
| `DEBOUNCE_S` | `0.8` | Minimum seconds between processing frames (prevents rapid-fire) |
---
## โฟ Accessibility Design
EchoLens is built with accessibility as a first-class concern:
| Feature | Implementation |
|---------|---------------|
| **ARIA live regions** | Screen readers auto-announce new descriptions via `aria-live="assertive"` |
| **Keyboard-first** | All core actions reachable without a mouse (D/R/P/Esc) |
| **Font scaling** | Three size levels (A / A+ / A++) via CSS class toggles on `` |
| **High contrast mode** | One-click toggle; increases contrast 1.7ร and adds dark borders |
| **Autoplay audio** | Descriptions play immediately; no extra click needed |
| **Large touch targets** | Buttons โฅ52 px height; full-width on mobile |
| **Focus indicators** | Visible 3 px focus rings on all interactive elements |
| **Status feedback** | Real-time status bar shows processing state, cache hits, word counts |
| **Screen-reader announcements** | JavaScript pushes button-action feedback to the ARIA live region |
---
## ๐งช Development
### Project structure
```
.
โโโ app.py # Main Gradio application
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ LICENSE # Apache 2.0
```
### Adding a new voice
Add an entry to `VOICE_MAP` in `app.py`:
```python
VOICE_MAP = {
# ... existing voices ...
"New Voice โ Female, CA": "en-CA-ClaraNeural",
}
```
Find available voices with `edge-tts --list-voices`.
### Adding a new task
1. Add to `TASKS` (human label โ Florence-2 token)
2. Add to `TASK_INFO` (tooltip description)
3. Set `MAX_TOKENS` for the token if needed
4. Add formatting logic in `_infer()` if the task needs custom output parsing
---
## ๐ค Model
[Microsoft Florence-2-base](https://huggingface.co/microsoft/Florence-2-base) โ a unified vision-language model that handles captioning, OCR, and object detection through task-specific prompt tokens. Runs in `float16` on CUDA and `float32` on CPU/MPS.
---
## ๐ License
Apache 2.0 โ see [LICENSE](LICENSE) for details.
---
## ๐ Acknowledgements
- [Microsoft Florence-2](https://huggingface.co/microsoft/Florence-2-base) for the vision-language model
- [Edge TTS](https://github.com/rany2/edge-tts) for free, high-quality neural text-to-speech
- [Gradio](https://gradio.app) for the accessible web UI framework
- [Hugging Face](https://huggingface.co) for model hosting and Spaces infrastructure
- [Transformers](https://github.com/huggingface/transformers) for the model inference pipeline