3v324v23 commited on
Commit
716dab2
·
1 Parent(s): b796c7d

fix missing credentials

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +28 -0
.gitignore CHANGED
@@ -5,6 +5,7 @@ g3/data/mp16/MP16_Pro_filtered.csv
5
  index
6
  checkpoints
7
  data
 
8
 
9
  # venv and dev stuff
10
  linuxenv
 
5
  index
6
  checkpoints
7
  data
8
+ keys
9
 
10
  # venv and dev stuff
11
  linuxenv
app.py CHANGED
@@ -14,6 +14,34 @@ from src.g3_batch_prediction import G3BatchPredictor
14
 
15
  from src.utils import load_images_as_base64
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  class EvidenceResponse(BaseModel):
19
  analysis: Annotated[
 
14
 
15
  from src.utils import load_images_as_base64
16
 
17
+ ENV = os.getenv("ENV")
18
+ cred_json = os.getenv("GOOGLE_CREDENTIALS_JSON")
19
+
20
+ if ENV == "hf":
21
+ if cred_json:
22
+ try:
23
+ # Parse để đảm bảo JSON hợp lệ
24
+ json.loads(cred_json)
25
+
26
+ file_path = "google-credentials.json"
27
+ with open(file_path, "w") as f:
28
+ f.write(cred_json)
29
+
30
+ # Set lại env để google auth tự nhận
31
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = file_path
32
+
33
+ print("[INFO] Google credentials saved to", file_path)
34
+
35
+ except json.JSONDecodeError:
36
+ print("[ERROR] GOOGLE_CREDENTIALS_JSON is not valid JSON")
37
+
38
+ else:
39
+ print("[ERROR] GOOGLE_CREDENTIALS_JSON is missing")
40
+
41
+ else:
42
+ # DEV mode (local)
43
+ print("[INFO] ENV != hf → skip Google credentials setup")
44
+
45
 
46
  class EvidenceResponse(BaseModel):
47
  analysis: Annotated[