Spaces:
Sleeping
Sleeping
File size: 10,260 Bytes
03229f8 179cb94 03229f8 8348919 15deac4 8348919 03229f8 |
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
---
title: Visual Product Matcher
emoji: ๐
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
---
# Visual Product Search ๐
An intelligent visual search engine that revolutionizes product discovery using state-of-the-art AI technology. This application combines CLIP (Contrastive Language-Image Pre-Training) with Qdrant vector database to enable semantic search across image collections, making it perfect for e-commerce, inventory management, and content discovery.
## ๐ Key Features
- ๐ฏ **Multi-Modal Search**: Search using text descriptions, uploaded images, or image URLs
- ๐ผ๏ธ **Smart Indexing**: Automatically indexes and monitors image folders with real-time updates
- ๐ **Semantic Understanding**: Uses OpenAI's CLIP model for deep image-text comprehension
- ๏ฟฝ **Similarity Scoring**: Provides percentage-based similarity scores for accurate results
- โก **Real-time Processing**: WebSocket-powered live progress updates during indexing
- ๐จ **Modern UI**: Clean, responsive interface with advanced search capabilities
- ๐ **URL Support**: Direct image search from web URLs
- ๐ฑ **Mobile Responsive**: Works seamlessly across all devices
## ๐ง Technical Approach & Solution
### Problem Statement
Traditional image search relies on metadata and filenames, which often fail to capture the actual visual content. Users struggle to find specific products or images without knowing exact file names or having perfect tagging systems.
### Our Solution Architecture
#### 1. **Multi-Modal Embedding Generation**
```
Text Query โ CLIP Text Encoder โ 512D Vector
Image Input โ CLIP Vision Encoder โ 512D Vector
URL Image โ Download โ CLIP Vision Encoder โ 512D Vector
```
#### 2. **Vector Similarity Search**
- **Database**: Qdrant cloud vector database for scalable similarity search
- **Indexing**: Real-time folder monitoring with automatic embedding generation
- **Storage**: Hybrid approach - embeddings in Qdrant, metadata in SQLite
#### 3. **Semantic Matching Pipeline**
```
User Input โ Feature Extraction โ Vector Search โ Similarity Ranking โ Results
```
### ๏ฟฝ๏ธ Architecture Components
#### Backend (FastAPI)
- **Image Processing**: PIL + CLIP for feature extraction
- **Vector Operations**: Qdrant client for similarity search
- **File Management**: Automatic folder monitoring and indexing
- **API Endpoints**: RESTful APIs for all search operations
#### Frontend (Modern Web UI)
- **Framework**: Vanilla JavaScript with Bootstrap 5
- **Styling**: Custom CSS with modern design principles
- **Real-time Updates**: WebSocket connections for live progress
- **Responsive Design**: Mobile-first approach
#### Database Layer
- **Vector Storage**: Qdrant cloud for embeddings and similarity search
- **Metadata Storage**: SQLite for image metadata and file information
- **Caching**: Thumbnail generation and caching for performance
## ๐ Quick Start
### Prerequisites
- Python 3.8+
- CUDA-compatible GPU (optional, recommended for performance)
- Qdrant Cloud account (free tier available)
### Installation
1. **Clone the repository**:
```bash
git clone https://github.com/itsfuad/SnapSeek
cd SnapSeek
```
2. **Create virtual environment**:
```bash
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
```
3. **Install dependencies**:
```bash
pip install -r requirements.txt
```
4. **Configure environment**:
Create a `.env` file:
```env
QDRANT_API_KEY=your_qdrant_api_key
QDRANT_URL=your_qdrant_cluster_url
```
5. **Launch the application**:
```bash
python app.py
```
6. **Access the interface**:
Open http://localhost:8000 in your browser
## ๐ฏ Usage Guide
### 1. **Index Your Images**
- Click "Add Folder" to select image directories
- Watch real-time indexing progress
- Images are automatically monitored for changes
### 2. **Search Methods**
#### Text Search
```
"red sports car"
"woman wearing blue dress"
"modern kitchen design"
```
#### Image Upload Search
- Click the image icon
- Upload a reference image
- Get visually similar results
#### URL Search
- Click the link icon
- Paste any image URL
- Find similar images in your collection
### 3. **Results & Insights**
- Similarity percentages for each match
- High-resolution image previews
- Metadata and file information
## ๐ญ Production Deployment
### Recommended Platforms
#### 1. **Railway (Recommended)**
- **Why**: Best for AI/ML applications with generous free tier
- **Resources**: 512MB RAM, 1GB storage
- **Benefits**: No sleep mode, automatic GitHub deployments
```dockerfile
# Dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
```
#### 2. **Render**
- **Resources**: 512MB RAM, 1GB storage
- **Benefits**: Free SSL, auto-deploy, no cold starts
#### 3. **Fly.io**
- **Resources**: 256MB RAM, 3GB storage volume
- **Benefits**: Global edge deployment, persistent volumes
### Environment Variables for Production
```env
QDRANT_API_KEY=your_production_key
QDRANT_URL=your_production_cluster
PORT=8000
DATA_DIR=/app/data
```
## ๐ ๏ธ Development & Testing
### Project Structure
```
SnapSeek/
โโโ app.py # FastAPI application
โโโ image_indexer.py # Image processing and indexing
โโโ image_search.py # Search logic and CLIP integration
โโโ image_database.py # Database operations
โโโ folder_manager.py # Folder monitoring and management
โโโ qdrant_singleton.py # Qdrant client management
โโโ requirements.txt # Dependencies
โโโ .env # Environment configuration
โโโ templates/
โ โโโ index.html # Main UI template
โโโ static/
โ โโโ js/
โ โ โโโ script.js # Frontend JavaScript
โ โโโ image.png # Application icon
โโโ config/
โ โโโ folders.json # Folder configuration
โโโ tests/
โโโ test_*.py # Test files
```
### Running Tests
```bash
pip install -r requirements-test.txt
pytest tests/ -v
```
### Development Setup
```bash
# Install development dependencies
pip install -r requirements-test.txt
# Run with auto-reload
uvicorn app:app --reload --host 0.0.0.0 --port 8000
```
## ๐ง Performance Optimization
### Model Selection
```python
# For production (smaller, faster)
MODEL_NAME = "openai/clip-vit-base-patch16"
# For development (balance)
MODEL_NAME = "openai/clip-vit-base-patch32"
```
### Hardware Recommendations
- **CPU**: 4+ cores for concurrent processing
- **RAM**: 8GB+ for model loading and image processing
- **Storage**: SSD recommended for faster I/O
- **GPU**: Optional, CUDA-compatible for faster inference
### Scaling Considerations
- **Batch Processing**: Process multiple images simultaneously
- **Caching**: Implement Redis for frequent queries
- **Load Balancing**: Use multiple instances for high traffic
- **Database Sharding**: Split collections by categories
## ๐ Troubleshooting
### Common Issues
#### 1. **Model Loading Errors**
```bash
# Clear cache and reinstall
pip uninstall torch torchvision transformers
pip install torch torchvision transformers --no-cache-dir
```
#### 2. **Qdrant Connection Issues**
- Verify API key and URL in `.env`
- Check network connectivity
- Ensure Qdrant cluster is active
#### 3. **Memory Issues**
- Reduce batch size in processing
- Use CPU-only mode: `device="cpu"`
- Close unused applications
#### 4. **Slow Performance**
- Enable GPU acceleration
- Optimize image sizes
- Implement result caching
### Performance Monitoring
```python
# Add logging for performance tracking
import time
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Time search operations
start_time = time.time()
results = await searcher.search_by_text(query)
logger.info(f"Search completed in {time.time() - start_time:.2f}s")
```
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Make your changes and add tests
4. Run tests: `pytest tests/`
5. Commit changes: `git commit -m "Add feature"`
6. Push to branch: `git push origin feature-name`
7. Create a Pull Request
### Code Standards
- Follow PEP 8 style guidelines
- Add docstrings to all functions
- Include type hints where appropriate
- Write tests for new features
## ๐ Use Cases & Applications
### E-commerce
- Product recommendation systems
- Visual search for online stores
- Inventory management
- Duplicate product detection
### Content Management
- Digital asset organization
- Stock photo searching
- Brand consistency checking
- Content moderation
### Research & Education
- Academic image databases
- Scientific data analysis
- Historical archive searches
- Educational content discovery
## ๐ฎ Future Enhancements
- [ ] **Multi-language Support**: Extend text search to multiple languages
- [ ] **Advanced Filters**: Add size, color, and metadata filters
- [ ] **Batch Operations**: Upload and search multiple images at once
- [ ] **API Integration**: RESTful API for external applications
- [ ] **Machine Learning**: Custom fine-tuned models for specific domains
- [ ] **Analytics Dashboard**: Search metrics and usage statistics
- [ ] **Mobile App**: Native mobile applications
- [ ] **Cloud Storage**: Integration with AWS S3, Google Drive, etc.
## ๐ License
This project is licensed under the Mozilla Public License 2.0 - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- **OpenAI**: For the CLIP model and research
- **Qdrant**: For the excellent vector database
- **FastAPI**: For the modern web framework
- **Transformers**: For the model implementation
- **Bootstrap**: For the UI components
## ๐ Support & Contact
- **Issues**: [GitHub Issues](https://github.com/itsfuad/SnapSeek/issues)
- **Discussions**: [GitHub Discussions](https://github.com/itsfuad/SnapSeek/discussions)
- **Documentation**: [Wiki](https://github.com/itsfuad/SnapSeek/wiki)
---
**Made with โค๏ธ by [itsfuad](https://github.com/itsfuad)**
*Revolutionizing visual search with AI technology*
|