Spaces:
Build error
Build error
Download server.py from xkailashhh/coco: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/xkailashhh/coco/resolve/main/server.py
- Command line
-
hf download hf://spaces/xkailashhh/coco/server.py
-
curl -L -o server.py https://huggingface.co/spaces/xkailashhh/coco/resolve/main/server.py
1.31 kB
| 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="/" | |
| ) | |
| 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) | |