yashvii commited on
Commit
1bb994f
·
verified ·
1 Parent(s): 22ce743

Update gradio_demo/app.py

Browse files
Files changed (1) hide show
  1. gradio_demo/app.py +16 -1
gradio_demo/app.py CHANGED
@@ -4,6 +4,7 @@ sys.path.append('./')
4
  from typing import Tuple
5
 
6
  import os
 
7
  import cv2
8
  import math
9
  import torch
@@ -43,7 +44,21 @@ import os
43
  # file.write(response.content)
44
 
45
  # print(f"Service account JSON file successfully downloaded")
46
- os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.getenv('GOOGLE_APPLICATION_CREDENTIALS')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "serviceaccount.json"
48
 
49
  # except requests.exceptions.RequestException as e:
 
4
  from typing import Tuple
5
 
6
  import os
7
+ import json
8
  import cv2
9
  import math
10
  import torch
 
44
  # file.write(response.content)
45
 
46
  # print(f"Service account JSON file successfully downloaded")
47
+ # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.getenv('GOOGLE_APPLICATION_CREDENTIALS')
48
+
49
+ service_account_json = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
50
+
51
+ if not service_account_json:
52
+ raise ValueError("The GCP_SERVICE_ACCOUNT secret is not set!")
53
+
54
+ # Write the JSON content to a temporary file
55
+ temp_credentials_path = "/tmp/service_account.json"
56
+
57
+ with open(temp_credentials_path, "w") as temp_file:
58
+ temp_file.write(service_account_json)
59
+
60
+ # Set the GOOGLE_APPLICATION_CREDENTIALS environment variable
61
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = temp_credentials_path
62
  # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "serviceaccount.json"
63
 
64
  # except requests.exceptions.RequestException as e: