# Image Encoder Microservice πŸ–ΌοΈ **Standalone service for vision-language learning** ## What It Does Converts any image into: - βœ… 512-dimensional CLIP embeddings - βœ… Text representation for LLMs - βœ… Auto-sends to cosmo-ai for learning - βœ… Runs on FREE HuggingFace CPU tier ## Quick Deploy 1. Create HuggingFace Space: - Name: `image-encoder` - SDK: **Docker** - Hardware: **CPU basic** (free tier) 2. Upload files from `/image-encoder/` folder 3. Update `COSMO_AI_URL` in `app.py` to your cosmo-ai URL 4. Deploy! βœ… ## How It Works ``` [User uploads image] ↓ [image-encoder processes with CLIP] ↓ [Converts to embedding + text] ↓ [Sends to cosmo-ai /api/feed/vision] ↓ [Cosmo-AI stores and learns] ``` ## API Usage ### Encode Image ```python import requests import base64 # Read image with open("photo.jpg", "rb") as f: img_data = base64.b64encode(f.read()).decode() # Encode and send to cosmo-ai response = requests.post( "https://YOUR-USERNAME-image-encoder.hf.space/encode", json={ "image_base64": img_data, "send_to_cosmo": True # Auto-send to cosmo-ai } ) print(response.json()) ``` ### Upload File ```python files = {"file": open("image.png", "rb")} response = requests.post( "https://YOUR-USERNAME-image-encoder.hf.space/encode/upload", files=files, params={"send_to_cosmo": True} ) ``` ## Features ### βœ… CPU Optimized - Uses CLIP-vit-base-patch32 (150MB) - Fast inference on free CPU - No GPU needed ### βœ… Auto Keepalive - Pings itself every 20 minutes - Prevents space from sleeping - Always available ### βœ… Cosmo-AI Integration - Automatic data sending - Vision feed endpoint - Learning from visual data ## Cosmo-AI Integration Cosmo-AI now has `/api/feed/vision` endpoint that: - βœ… Receives image embeddings - βœ… Stores up to 1000 images - βœ… Provides stats and samples - βœ… Enables vision-language learning Check stats: ```bash curl https://shubhjn-cosmo-ai.hf.space/api/feed/vision/stats ``` ## Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ image-encoder │──────▢│ cosmo-ai β”‚ β”‚ (CPU Space) β”‚ REST β”‚ (Main App) β”‚ β”‚ β”‚ API β”‚ β”‚ β”‚ β€’ CLIP Model β”‚ β”‚ β€’ LLM β”‚ β”‚ β€’ Encoding β”‚ β”‚ β€’ Chat β”‚ β”‚ β€’ Keepalive β”‚ β”‚ β€’ Vision Feed β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Free & Independent - πŸ†“ Both services run on FREE HuggingFace tier - πŸ”“ No restrictions, no API limits - πŸš€ Independent microservices - ♾️ Keepalive prevents sleeping Deploy and enjoy vision-enabled AI! πŸŽ‰