THED2 commited on
Commit
a0659e8
ยท
verified ยท
1 Parent(s): 85a3aba

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -9
main.py CHANGED
@@ -10,22 +10,32 @@ os.makedirs(hermes_dir, exist_ok=True)
10
 
11
  print("[1] Setting up configs and skills...")
12
 
13
- # --- Secrets Load (Hugging Face Env Variables se) ---
14
  OR_KEY = os.getenv('OPENROUTER_API_KEY')
15
  NV_KEY = os.getenv('NVIDIA_API_KEY')
16
  TG_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
17
  TG_USER = os.getenv('TELEGRAM_ALLOWED_USERS')
18
 
19
- if not all([OR_KEY, NV_KEY, TG_TOKEN, TG_USER]):
20
- print("โŒ ERROR: Hugging Face Spaces me Repository Secrets/Env Variables missing hain!")
 
 
 
 
 
 
 
21
  sys.exit(1)
22
 
 
 
 
23
  # --- Write .env ---
24
  with open(os.path.join(hermes_dir, ".env"), "w") as f:
25
  f.write(f"OPENROUTER_API_KEY={OR_KEY}\n")
26
  f.write(f"NVIDIA_API_KEY={NV_KEY}\n")
27
  f.write(f"TELEGRAM_BOT_TOKEN={TG_TOKEN}\n")
28
- f.write(f"TELEGRAM_ALLOWED_USERS={TG_USER}\n")
29
 
30
  # --- Write config.yaml (NVIDIA Primary) ---
31
  with open(os.path.join(hermes_dir, "config.yaml"), "w") as f:
@@ -73,9 +83,9 @@ print("โœ… Config and Skills created successfully.")
73
 
74
  # --- Start Hermes Gateway ---
75
  print("[2] Launching Hermes Telegram Gateway...")
76
- hermes_bin = shutil.which("hermes") or os.path.expanduser("~/.local/bin/hermes")
77
 
78
- # Live log output taaki Hugging Face logs me sab dikhe
79
  process = subprocess.Popen(
80
  [hermes_bin, "gateway", "start"],
81
  env=os.environ,
@@ -85,10 +95,8 @@ process = subprocess.Popen(
85
 
86
  print("๐Ÿš€ Bot is live on Hugging Face Server! Keeping process alive...")
87
 
88
- # Main execution loop jo container ko running rakhega bina freeze hue
89
  try:
90
  while True:
91
- # Check if process died
92
  if process.poll() is not None:
93
  print("โš ๏ธ Hermes process ended unexpectedly. Restarting...")
94
  process = subprocess.Popen([hermes_bin, "gateway", "start"], env=os.environ, stdout=sys.stdout, stderr=sys.stderr)
@@ -96,4 +104,3 @@ try:
96
  except KeyboardInterrupt:
97
  print("๐Ÿ›‘ Stopping server.")
98
  process.terminate()
99
-
 
10
 
11
  print("[1] Setting up configs and skills...")
12
 
13
+ # --- Secrets Load ---
14
  OR_KEY = os.getenv('OPENROUTER_API_KEY')
15
  NV_KEY = os.getenv('NVIDIA_API_KEY')
16
  TG_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
17
  TG_USER = os.getenv('TELEGRAM_ALLOWED_USERS')
18
 
19
+ # Debugging lines taaki exact pata chale kaunsa secret nahi mil raha
20
+ if not OR_KEY: print("โš ๏ธ Warning: OPENROUTER_API_KEY is empty or missing!")
21
+ if not NV_KEY: print("โš ๏ธ Warning: NVIDIA_API_KEY is empty or missing!")
22
+ if not TG_TOKEN: print("โš ๏ธ Warning: TELEGRAM_BOT_TOKEN is empty or missing!")
23
+ if not TG_USER: print("โš ๏ธ Warning: TELEGRAM_ALLOWED_USERS is empty or missing!")
24
+
25
+ # Strict crash hata kar fallback check lagaya hai
26
+ if not TG_TOKEN or not TG_USER:
27
+ print("โŒ ERROR: Main Telegram credentials missing hain! Check your Hugging Face Secrets.")
28
  sys.exit(1)
29
 
30
+ # Ensure string conversion for safe file writing
31
+ TG_USER_STR = str(TG_USER).strip()
32
+
33
  # --- Write .env ---
34
  with open(os.path.join(hermes_dir, ".env"), "w") as f:
35
  f.write(f"OPENROUTER_API_KEY={OR_KEY}\n")
36
  f.write(f"NVIDIA_API_KEY={NV_KEY}\n")
37
  f.write(f"TELEGRAM_BOT_TOKEN={TG_TOKEN}\n")
38
+ f.write(f"TELEGRAM_ALLOWED_USERS={TG_USER_STR}\n")
39
 
40
  # --- Write config.yaml (NVIDIA Primary) ---
41
  with open(os.path.join(hermes_dir, "config.yaml"), "w") as f:
 
83
 
84
  # --- Start Hermes Gateway ---
85
  print("[2] Launching Hermes Telegram Gateway...")
86
+ hermes_bin = shutil.which("hermes") or "/usr/local/bin/hermes"
87
 
88
+ # Process running
89
  process = subprocess.Popen(
90
  [hermes_bin, "gateway", "start"],
91
  env=os.environ,
 
95
 
96
  print("๐Ÿš€ Bot is live on Hugging Face Server! Keeping process alive...")
97
 
 
98
  try:
99
  while True:
 
100
  if process.poll() is not None:
101
  print("โš ๏ธ Hermes process ended unexpectedly. Restarting...")
102
  process = subprocess.Popen([hermes_bin, "gateway", "start"], env=os.environ, stdout=sys.stdout, stderr=sys.stderr)
 
104
  except KeyboardInterrupt:
105
  print("๐Ÿ›‘ Stopping server.")
106
  process.terminate()