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)