muhammad-abdullah commited on
Commit
548fae0
·
1 Parent(s): eac03db
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -29,7 +29,22 @@ import vertexai.preview.generative_models as generative_models
29
  import time
30
  import typing_extensions as typing
31
  import os
32
- os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  vertexai.init(project="wubble2024", location="asia-southeast1")
34
  torch.set_default_device("cpu")
35
  # Initialize the text-to-image pipeline
 
29
  import time
30
  import typing_extensions as typing
31
  import os
32
+ import json
33
+ import tempfile
34
+
35
+ # Retrieve the JSON string from the environment variable
36
+ google_creds_json = os.getenv('GOOGLE_APPLICATION_CREDENTIALS_JSON')
37
+
38
+ if google_creds_json:
39
+ # Create a temporary file to store the credentials
40
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
41
+ temp_file.write(google_creds_json.encode('utf-8'))
42
+ temp_file_path = temp_file.name
43
+
44
+ # Set the environment variable to point to this temporary file
45
+ os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = temp_file_path
46
+ else:
47
+ raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON environment variable is not set.")
48
  vertexai.init(project="wubble2024", location="asia-southeast1")
49
  torch.set_default_device("cpu")
50
  # Initialize the text-to-image pipeline