import os import time import random import threading import requests import nest_asyncio import uvicorn from fastapi import FastAPI app = FastAPI( title="UltXtraHF", version="1.0.2", contact={ "name": "🌀ʊʄ⊕ք🌀", "url": "https://github.com/ufoptg/UltroidBackup/", }, docs_url=None, redoc_url="/" ) @app.get("/status") def status(): return {"message": "running"} # ----------------- KEEP SPACE ALIVE ----------------- # def keep_alive(): """ Pings the HuggingFace app, but only between 2 to 8 hours gap. Prevents the space sleep on long idles. """ url = os.getenv("SPACE_URL") if not url: url = "https://xkailashhh-coco.hf.space/status" headers = {"content-type":"application/json"} while True: try: haha = requests.get(url, headers=headers, timeout=10) print(haha.json()) except Exception as lol: print(lol) time.sleep(random.randint(7200, 28800)) def start_keepalive_thread(): t = threading.Thread(target=keep_alive) t.daemon = True t.start() # ----------------------------------------------------- # if __name__ == "__main__": start_keepalive_thread() nest_asyncio.apply() uvicorn.run(app, host="0.0.0.0", port=7860)