Configure Vertex service account JSON bootstrap

#1
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,13 +1,43 @@
1
  """Gradio UI wired to hexagonal architecture services."""
2
  from __future__ import annotations
3
 
 
4
  import os
 
5
  from dotenv import load_dotenv
6
 
7
  load_dotenv()
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  print(f"DEBUG: CWD is {os.getcwd()}")
10
  print(f"DEBUG: SUPABASE_URL present: {bool(os.environ.get('SUPABASE_URL'))}")
 
11
 
12
  from calls_analyser.ui import config as ui_config
13
  from calls_analyser.ui.dependencies import build_dependencies
 
1
  """Gradio UI wired to hexagonal architecture services."""
2
  from __future__ import annotations
3
 
4
+ import json
5
  import os
6
+ import tempfile
7
  from dotenv import load_dotenv
8
 
9
  load_dotenv()
10
 
11
+ # ---------------------------------------------------------------------------
12
+ # Google Service Account credentials bootstrap for Vertex AI.
13
+ #
14
+ # In Hugging Face Spaces, store the full service-account key JSON in the
15
+ # secret GOOGLE_SERVICE_ACCOUNT_JSON. This writes it to a temporary file and
16
+ # exposes GOOGLE_APPLICATION_CREDENTIALS so google-genai / Vertex clients can
17
+ # use Application Default Credentials.
18
+ # ---------------------------------------------------------------------------
19
+ if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
20
+ sa_json = os.environ.get("GOOGLE_SERVICE_ACCOUNT_JSON", "").strip()
21
+ if sa_json:
22
+ try:
23
+ json.loads(sa_json)
24
+ tmp = tempfile.NamedTemporaryFile(
25
+ mode="w",
26
+ suffix=".json",
27
+ delete=False,
28
+ prefix="gcp_sa_",
29
+ encoding="utf-8",
30
+ )
31
+ tmp.write(sa_json)
32
+ tmp.close()
33
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = tmp.name
34
+ print(f"DEBUG: Wrote service-account credentials to {tmp.name}")
35
+ except (json.JSONDecodeError, OSError) as exc:
36
+ print(f"WARNING: GOOGLE_SERVICE_ACCOUNT_JSON is set but invalid: {exc}")
37
+
38
  print(f"DEBUG: CWD is {os.getcwd()}")
39
  print(f"DEBUG: SUPABASE_URL present: {bool(os.environ.get('SUPABASE_URL'))}")
40
+ print(f"DEBUG: GOOGLE_APPLICATION_CREDENTIALS: {os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', '(not set)')}")
41
 
42
  from calls_analyser.ui import config as ui_config
43
  from calls_analyser.ui.dependencies import build_dependencies
requirements.txt CHANGED
@@ -3,10 +3,12 @@ pandas>=2.2.2
3
  numpy>=1.26.4
4
  soundfile>=0.12.1
5
  google-genai>=0.6.0
 
6
  gradio
7
  pydantic>=2.7.0
8
  pytest>=8.2.0
9
  APScheduler
 
10
  supabase
11
  git+https://github.com/tuteishygpt/CallsAnaliser.git@main
12
  #
 
3
  numpy>=1.26.4
4
  soundfile>=0.12.1
5
  google-genai>=0.6.0
6
+ google-cloud-storage>=2.14.0
7
  gradio
8
  pydantic>=2.7.0
9
  pytest>=8.2.0
10
  APScheduler
11
+ python-dotenv>=1.0.0
12
  supabase
13
  git+https://github.com/tuteishygpt/CallsAnaliser.git@main
14
  #