Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,385 Bytes
7a6c881 |
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 |
#!/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() |