Download hermes_run.py from lenson78/hermes: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/spaces/lenson78/hermes/resolve/main/hermes_run.py
- Command line
-
hf download hf://spaces/lenson78/hermes/hermes_run.py
-
curl -L -o hermes_run.py https://huggingface.co/spaces/lenson78/hermes/resolve/main/hermes_run.py
2.64 kB
| #!/usr/bin/env python3 | |
| """Hermes gateway runner with DNS fix for HF Spaces health check.""" | |
| import sys | |
| import os | |
| import signal | |
| import time | |
| print('[Hermes] ===== STARTING hermes_run.py =====', flush=True) | |
| print(f'[Hermes] PID: {os.getpid()}', flush=True) | |
| # Timeout handler | |
| def timeout_handler(signum, frame): | |
| print('[Hermes] ERROR: Gateway startup timeout (60s)', file=sys.stderr, flush=True) | |
| sys.exit(1) | |
| # Set 60 second timeout for gateway startup | |
| signal.signal(signal.SIGALRM, timeout_handler) | |
| signal.alarm(60) | |
| print('[Hermes] Step 1/6: Setting up DNS fix...', flush=True) | |
| import socket | |
| TG_IP = '149.154.167.220' | |
| _orig_gi = socket.getaddrinfo | |
| def _hijacked_gi(host, port, *args, **kwargs): | |
| h = str(host).lower() if host else '' | |
| if 'telegram' in h or '.t.me' in h: | |
| print(f'[DNS] {host} -> {TG_IP}', file=sys.stderr, flush=True) | |
| return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (TG_IP, port or 443))] | |
| return _orig_gi(host, port, *args, **kwargs) | |
| socket.getaddrinfo = _hijacked_gi | |
| print('[Hermes] Step 1/6: DNS fix done', flush=True) | |
| print('[Hermes] Step 2/6: Starting health server...', flush=True) | |
| import threading | |
| from http.server import HTTPServer, BaseHTTPRequestHandler | |
| from datetime import datetime | |
| import json | |
| class HealthHandler(BaseHTTPRequestHandler): | |
| def do_GET(self): | |
| if self.path == '/health': | |
| self.send_response(200) | |
| self.send_header('Content-type', 'text/plain') | |
| self.end_headers() | |
| self.wfile.write(b'ok') | |
| else: | |
| self.send_response(200) | |
| self.send_header('Content-type', 'application/json') | |
| self.end_headers() | |
| self.wfile.write(json.dumps({ | |
| 'status': 'ok', | |
| 'timestamp': datetime.now().isoformat() | |
| }).encode()) | |
| def log_message(self, *args): | |
| pass | |
| server = HTTPServer(('0.0.0.0', 7860), HealthHandler) | |
| thread = threading.Thread(target=server.serve_forever, daemon=True) | |
| thread.start() | |
| print('[Hermes] Step 2/6: Health server started on port 7860', flush=True) | |
| print('[Hermes] Step 3/6: Supabase upload handled by setup.sh (background process)', flush=True) | |
| print('[Hermes] Step 4/6: Importing gateway.run...', flush=True) | |
| import asyncio | |
| from gateway.run import main | |
| print('[Hermes] Step 4/6: gateway.run imported', flush=True) | |
| print('[Hermes] Step 5/6: Starting gateway main loop...', flush=True) | |
| signal.alarm(0) # Cancel alarm - gateway is starting | |
| try: | |
| asyncio.run(main()) | |
| except Exception as e: | |
| print(f'[Hermes] Gateway crashed: {e}', file=sys.stderr, flush=True) | |
| time.sleep(5) | |
| sys.exit(1) | |