mominah commited on
Commit
c9b5f23
Β·
verified Β·
1 Parent(s): 67b16fb

Update video_rag_routes.py

Browse files
Files changed (1) hide show
  1. video_rag_routes.py +24 -20
video_rag_routes.py CHANGED
@@ -17,30 +17,34 @@ from langchain_groq import ChatGroq
17
 
18
  # β€”β€”β€” Rotate Gemini API keys from HF Secrets β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
19
  #
20
- # In your Space’s Secrets UI, create a comma-separated list under
21
- # Key: GOOGLE_API_KEY_NAMES
22
- # Value: G_API,GO_API,GOO_API,GOOG_API,GOOGL_API,GOOGLE_API
 
23
  #
24
- # Then also define each of those six as individual secrets:
25
- # G_API=AIzaS…1lLXA
26
- # GO_API=AIzaS…QtkOT8
27
- # …etc…
28
- #
29
- _key_names = os.environ.get("GOOGLE_API_KEY_NAMES", "")
30
- if not _key_names:
 
 
 
 
 
 
 
 
 
 
 
31
  raise RuntimeError(
32
- "You must define a HF Secret named GOOGLE_API_KEY_NAMES "
33
- "(e.g. 'G_API,GO_API,…')"
34
  )
35
 
36
- _key_names = [n.strip() for n in _key_names.split(",") if n.strip()]
37
- _api_keys = []
38
- for name in _key_names:
39
- val = os.environ.get(name)
40
- if not val:
41
- raise RuntimeError(f"Hugging Face Secret `{name}` is not set")
42
- _api_keys.append(val)
43
-
44
  _key_cycle = itertools.cycle(_api_keys)
45
 
46
  def init_google_client():
 
17
 
18
  # β€”β€”β€” Rotate Gemini API keys from HF Secrets β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
19
  #
20
+ # You can still optionally define:
21
+ # GOOGLE_API_KEY_NAMES = "G_API,GO_API,…"
22
+ # as a comma-separated list of secret names. But if you don’t,
23
+ # we’ll auto-discover all secrets whose values start with "AIzaSy".
24
  #
25
+ _key_names_env = os.environ.get("GOOGLE_API_KEY_NAMES", "").strip()
26
+ if _key_names_env:
27
+ # User has explicitly listed which secrets to use
28
+ _key_names = [n.strip() for n in _key_names_env.split(",") if n.strip()]
29
+ _api_keys = []
30
+ for name in _key_names:
31
+ val = os.environ.get(name)
32
+ if not val:
33
+ raise RuntimeError(f"Hugging Face Secret `{name}` is not set")
34
+ _api_keys.append(val)
35
+ else:
36
+ # Auto-discover any secret value that looks like a Google key
37
+ _api_keys = [
38
+ v for v in os.environ.values()
39
+ if isinstance(v, str) and v.startswith("AIzaSy")
40
+ ]
41
+
42
+ if not _api_keys:
43
  raise RuntimeError(
44
+ "No Google API keys found in environment. "
45
+ "Either set `GOOGLE_API_KEY_NAMES` or add secrets whose values start with 'AIzaSy'."
46
  )
47
 
 
 
 
 
 
 
 
 
48
  _key_cycle = itertools.cycle(_api_keys)
49
 
50
  def init_google_client():