Tu Nombre commited on
Commit
4705133
·
1 Parent(s): 3c8f3ce

3 keys groq rotacion automatica

Browse files
Files changed (2) hide show
  1. cliente_template.py +19 -2
  2. main.py +1 -1
cliente_template.py CHANGED
@@ -36,7 +36,11 @@ try:
36
  print("Token descargado", flush=True)
37
  except Exception as e:
38
  print(f"Sin token aún: {e}", flush=True)
39
- GROQ_KEY = "GROQ_PLACEHOLDER"
 
 
 
 
40
  TIPO_VIDEO = "TIPO_PLACEHOLDER"
41
  PEXELS_KEY = "PEXELS_PLACEHOLDER"
42
  LOGS = []
@@ -50,7 +54,20 @@ def log(msg):
50
 
51
  def generar_guion():
52
  _tono_actual = CONFIG.get("tono", "educativo")
53
- client = Groq(api_key=GROQ_KEY)
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  _canal_url = CONFIG.get("canal_promocionar", "").strip()
55
  _contexto_canal = f" El video debe ser un teaser que invite a ver el canal {_canal_url}." if _canal_url else ""
56
  res = client.chat.completions.create(
 
36
  print("Token descargado", flush=True)
37
  except Exception as e:
38
  print(f"Sin token aún: {e}", flush=True)
39
+ GROQ_KEYS = ["GROQ_PLACEHOLDER", "GROQ_PLACEHOLDER_2", "GROQ_PLACEHOLDER_3"]
40
+ GROQ_KEYS = [k for k in GROQ_KEYS if k and not k.startswith("GROQ_PLACEHOLDER")]
41
+ if not GROQ_KEYS:
42
+ GROQ_KEYS = ["GROQ_PLACEHOLDER"]
43
+ GROQ_KEY = GROQ_KEYS[0]
44
  TIPO_VIDEO = "TIPO_PLACEHOLDER"
45
  PEXELS_KEY = "PEXELS_PLACEHOLDER"
46
  LOGS = []
 
54
 
55
  def generar_guion():
56
  _tono_actual = CONFIG.get("tono", "educativo")
57
+ last_err = None
58
+ for _key in GROQ_KEYS:
59
+ try:
60
+ client = Groq(api_key=_key)
61
+ return _generar_guion_con(client, _tono_actual)
62
+ except Exception as _e:
63
+ last_err = _e
64
+ if "rate_limit" in str(_e).lower() or "429" in str(_e):
65
+ continue
66
+ else:
67
+ raise
68
+ raise last_err if last_err else Exception("Sin keys Groq")
69
+
70
+ def _generar_guion_con(client, _tono_actual):
71
  _canal_url = CONFIG.get("canal_promocionar", "").strip()
72
  _contexto_canal = f" El video debe ser un teaser que invite a ver el canal {_canal_url}." if _canal_url else ""
73
  res = client.chat.completions.create(
main.py CHANGED
@@ -146,7 +146,7 @@ async def crear_space(nicho: str, email: str, tipo: str = "largo", config_parsed
146
  headers = {"Authorization": f"Bearer {token_actual}", "Content-Type": "application/json"}
147
 
148
  with open("cliente_template.py", "r") as _f:
149
- main_code = _f.read().replace("NICHO_PLACEHOLDER", nicho).replace("EMAIL_PLACEHOLDER", email).replace("REPO_PLACEHOLDER", f"{hf_user_actual}/{space_id}").replace("GROQ_PLACEHOLDER", os.environ.get("GROQ_KEY","")).replace("PEXELS_PLACEHOLDER", os.environ.get("PEXELS_KEY","")).replace("TIPO_PLACEHOLDER", tipo).replace("CONFIG_PLACEHOLDER", __import__("json").dumps(config_parsed or {}))
150
 
151
  req = "gradio\ngroq\nedge-tts\nmoviepy==1.0.3\nrequests\nhttpx\ngoogle-api-python-client\ngoogle-auth\ngoogle-auth-oauthlib\nimageio\nimageio-ffmpeg\ndecorator\ntqdm\nPillow\nnumpy\nopencv-python-headless"
152
 
 
146
  headers = {"Authorization": f"Bearer {token_actual}", "Content-Type": "application/json"}
147
 
148
  with open("cliente_template.py", "r") as _f:
149
+ main_code = _f.read().replace("NICHO_PLACEHOLDER", nicho).replace("EMAIL_PLACEHOLDER", email).replace("REPO_PLACEHOLDER", f"{hf_user_actual}/{space_id}").replace("GROQ_PLACEHOLDER", os.environ.get("GROQ_KEY","")).replace("GROQ_PLACEHOLDER_2", os.environ.get("GROQ_KEY_2","")).replace("GROQ_PLACEHOLDER_3", os.environ.get("GROQ_KEY_3","")).replace("PEXELS_PLACEHOLDER", os.environ.get("PEXELS_KEY","")).replace("TIPO_PLACEHOLDER", tipo).replace("CONFIG_PLACEHOLDER", __import__("json").dumps(config_parsed or {}))
150
 
151
  req = "gradio\ngroq\nedge-tts\nmoviepy==1.0.3\nrequests\nhttpx\ngoogle-api-python-client\ngoogle-auth\ngoogle-auth-oauthlib\nimageio\nimageio-ffmpeg\ndecorator\ntqdm\nPillow\nnumpy\nopencv-python-headless"
152