Spaces:
Running
Running
| # Image Encoder - Keepalive Configuration | |
| ## How Keepalive Works | |
| The image-encoder has a **built-in keepalive mechanism** that prevents HuggingFace Spaces from pausing. | |
| ## Features | |
| ### π Automatic Self-Ping | |
| - Pings itself every **30 minutes** via HTTP | |
| - Starts automatically on service startup | |
| - Runs in background (non-blocking) | |
| ### π― How It Works | |
| ``` | |
| [Service starts] | |
| β | |
| [Wait 2 minutes for full startup] | |
| β | |
| [Every 30 minutes:] | |
| β | |
| [GET /ping endpoint] | |
| β | |
| [Logs success/failure] | |
| β | |
| [Repeat forever] | |
| ``` | |
| ### π Monitoring | |
| View keepalive status in logs: | |
| ``` | |
| π Keepalive started - will ping https://your-space.hf.space/ping every 30 minutes | |
| π Keepalive ping successful | |
| ``` | |
| ### π Manual Trigger | |
| You can manually trigger keepalive: | |
| ```bash | |
| curl -X POST https://YOUR-USERNAME-image-encoder.hf.space/keepalive/trigger | |
| ``` | |
| This also pings cosmo-ai to keep both services alive! | |
| ## Environment Variables | |
| Set `SPACE_HOST` to your HuggingFace Space URL (optional): | |
| ``` | |
| SPACE_HOST=https://username-image-encoder.hf.space | |
| ``` | |
| If not set, auto-detects from HuggingFace environment. | |
| ## Why Every 30 Minutes? | |
| - HuggingFace pauses spaces after **48 hours** of no activity | |
| - HTTP requests count as activity | |
| - 30-minute interval is safe and efficient | |
| - Conserves resources while staying active | |
| ## Failsafe | |
| If a ping fails: | |
| - β Logs the error | |
| - β Continues trying | |
| - β Doesn't crash the service | |
| The keepalive loop is resilient and won't stop even if individual pings fail. | |
| ## Combined with Cosmo-AI | |
| Both services can keep each other alive: | |
| 1. **image-encoder** pings itself every 30 min | |
| 2. **cosmo-ai** has its own HF model keepalive | |
| 3. They ping each other when exchanging data | |
| Result: **Both services stay active 24/7 on free tier!** π | |