--- 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 [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://lovnishverma-imagecaptioningai.hf.space/) [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) [![Gradio](https://img.shields.io/badge/Gradio-5.34.2-orange)](https://gradio.app) [![Model: Florence-2](https://img.shields.io/badge/Model-Florence--2--base-purple)](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