Spaces:
Running
Running
| import os | |
| import logging | |
| import requests | |
| from fastapi import FastAPI | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger("hf-keepalive") | |
| app = FastAPI() | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| # All private spaces | |
| SPACES = [ | |
| "https://jebin2-captioncreator.hf.space/run-command/create_publish?type=chess,pexels&id=onetime", | |
| "https://jebin2-comic-panel-extractor.hf.space/", | |
| "https://jebin2-paper.hf.space/", | |
| "https://jebin2-stt.hf.space/", | |
| "https://jebin2-tts.hf.space/", | |
| "https://jebin2-ttt.hf.space/", | |
| ] | |
| TIMEOUT = 120 | |
| def home(): | |
| return {"status": "alive"} | |
| def trigger_all(): | |
| logger.info("Keepalive triggered. Calling all spaces...") | |
| headers = {"Authorization": f"Bearer {HF_TOKEN}"} | |
| for url in SPACES: | |
| try: | |
| logger.info(f"Calling {url}") | |
| requests.get(url, headers=headers, timeout=TIMEOUT) | |
| except Exception as e: | |
| logger.warning(f"Failed: {url} -> {e}") | |
| # No heavy response needed | |
| return "OK" | |