Spaces:
Sleeping

File size: 843 Bytes
d121d13
 
ec5679c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import base64
import threading
import time
import urllib.request

# Keep-alive functionality
def keep_alive():
    space_host = os.environ.get("SPACE_HOST", "")
    if space_host:
        ping_url = f"https://{space_host}"
        while True:
            try:
                urllib.request.urlopen(ping_url, timeout=10)
                print(f"[Keep-Alive] Pinged at {time.strftime('%H:%M:%S')}")
            except:
                pass
            time.sleep(600)

threading.Thread(target=keep_alive, daemon=True).start()

# Load and run the main code
main_code = os.environ.get("MAIN_CODE", "")
if not main_code:
    print("ERROR: MAIN_CODE secret not found!")
    print("Please add the MAIN_CODE secret in Hugging Face Space settings.")
else:
    decoded_code = base64.b64decode(main_code).decode('utf-8')
    exec(decoded_code)