Spaces:
Build error
Build error
File size: 1,309 Bytes
a5dd9cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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)
|