Spaces:
Running
on
Zero
Running
on
Zero
#!/usr/bin/env python3 | |
""" | |
Manual keep-alive script for Tranception Space | |
Run this locally to keep your Space active | |
""" | |
import requests | |
import time | |
from datetime import datetime | |
SPACE_URL = "https://huggingface.co/spaces/MoraxCheng/Transeption_iGEM_BASISCHINA_2025" | |
PING_INTERVAL = 300 # 5 minutes | |
def ping_space(): | |
"""Ping the Space to keep it alive""" | |
try: | |
print(f"[{datetime.now()}] Pinging Space...") | |
response = requests.get(SPACE_URL, timeout=30) | |
if response.status_code == 200: | |
print(f"✓ Space is alive (HTTP {response.status_code})") | |
return True | |
else: | |
print(f"⚠ Space returned HTTP {response.status_code}") | |
return False | |
except requests.exceptions.Timeout: | |
print("⚠ Request timed out - Space might be starting up") | |
return False | |
except Exception as e: | |
print(f"✗ Error: {e}") | |
return False | |
def main(): | |
print(f"Starting keep-alive for: {SPACE_URL}") | |
print(f"Ping interval: {PING_INTERVAL} seconds") | |
print("Press Ctrl+C to stop\n") | |
while True: | |
try: | |
ping_space() | |
print(f"Next ping in {PING_INTERVAL} seconds...\n") | |
time.sleep(PING_INTERVAL) | |
except KeyboardInterrupt: | |
print("\nStopped by user") | |
break | |
if __name__ == "__main__": | |
main() |