qqwjq1981 commited on
Commit
1b84c33
·
verified ·
1 Parent(s): 2a1ff53

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -63,6 +63,7 @@ from requests.auth import HTTPBasicAuth
63
 
64
  from google.cloud import storage, exceptions # Import exceptions for error handling
65
  from google.cloud.exceptions import NotFound
 
66
 
67
 
68
  import logging
@@ -85,7 +86,7 @@ account_sid = os.environ["TWILLO_ACCOUNT_SID"]
85
  auth_token = os.environ["TWILLO_AUTH_TOKEN"]
86
  twilio_phone_number = os.environ["TWILLO_PHONE_NUMBER"]
87
 
88
-
89
  twillo_client = Client(account_sid, auth_token)
90
 
91
  # Set the GOOGLE_APPLICATION_CREDENTIALS environment variable
@@ -336,6 +337,11 @@ def generate_task_hash(task_description):
336
  return 'output'
337
 
338
  def save_to_google_storage(bucket_name, file_path, destination_blob_name, expiration_minutes = 1440):
 
 
 
 
 
339
  gcs_client = storage.Client() # Initialize Google Cloud Storage client
340
 
341
  # Check if the bucket exists; if not, create it
 
63
 
64
  from google.cloud import storage, exceptions # Import exceptions for error handling
65
  from google.cloud.exceptions import NotFound
66
+ from google.oauth2 import service_account
67
 
68
 
69
  import logging
 
86
  auth_token = os.environ["TWILLO_AUTH_TOKEN"]
87
  twilio_phone_number = os.environ["TWILLO_PHONE_NUMBER"]
88
 
89
+ google_credentials_json = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
90
  twillo_client = Client(account_sid, auth_token)
91
 
92
  # Set the GOOGLE_APPLICATION_CREDENTIALS environment variable
 
337
  return 'output'
338
 
339
  def save_to_google_storage(bucket_name, file_path, destination_blob_name, expiration_minutes = 1440):
340
+ credentials_dict = json.loads(google_credentials_json)
341
+
342
+ # Step 3: Use `service_account.Credentials.from_service_account_info` to authenticate directly with the JSON
343
+ credentials = service_account.Credentials.from_service_account_info(credentials_dict)
344
+
345
  gcs_client = storage.Client() # Initialize Google Cloud Storage client
346
 
347
  # Check if the bucket exists; if not, create it