Léo Bourrel commited on
Commit
687f595
·
1 Parent(s): 150c5ae

remove dependency

Browse files
src/app.py CHANGED
@@ -18,7 +18,7 @@ engine, session = get_db_connection()
18
  park_manager = ParkManager()
19
  image_manager = ImageManager()
20
  openai_manager = OpenAIManager()
21
- gcs = GoogleCloudStorage("ialab-fr-7047e56bef0b.json")
22
 
23
 
24
  def get_image_predictions(images: list[dict]) -> dict:
 
18
  park_manager = ParkManager()
19
  image_manager = ImageManager()
20
  openai_manager = OpenAIManager()
21
+ gcs = GoogleCloudStorage()
22
 
23
 
24
  def get_image_predictions(images: list[dict]) -> dict:
src/cloud_storage/google_cloud_storage.py CHANGED
@@ -5,11 +5,14 @@ from .base_storage import BaseStorage
5
 
6
 
7
  class GoogleCloudStorage(BaseStorage):
8
- def __init__(self, service_account_path: str):
9
- credentials = service_account.Credentials.from_service_account_file(
10
- service_account_path
11
- )
12
- self.client = storage.Client(credentials=credentials)
 
 
 
13
 
14
  def upload_file_from_content(
15
  self, bucket_name: str, bucket_file_path: str, file_content: bytes
@@ -43,7 +46,7 @@ class GoogleCloudStorage(BaseStorage):
43
  Returns:
44
  bytes: Content of the blob
45
  """
46
- bucket = self.client.get_bucket(bucket_name)
47
  source_blob_name = source_blob_name.replace(f"gs://{bucket_name}/", "")
48
  blob = bucket.blob(source_blob_name)
49
  return blob.download_as_bytes()
 
5
 
6
 
7
  class GoogleCloudStorage(BaseStorage):
8
+ def __init__(self, service_account_path: str | None = None):
9
+ if service_account_path:
10
+ credentials = service_account.Credentials.from_service_account_file(
11
+ service_account_path
12
+ )
13
+ self.client = storage.Client(credentials=credentials)
14
+ else:
15
+ self.client = storage.Client.create_anonymous_client()
16
 
17
  def upload_file_from_content(
18
  self, bucket_name: str, bucket_file_path: str, file_content: bytes
 
46
  Returns:
47
  bytes: Content of the blob
48
  """
49
+ bucket = self.client.bucket(bucket_name)
50
  source_blob_name = source_blob_name.replace(f"gs://{bucket_name}/", "")
51
  blob = bucket.blob(source_blob_name)
52
  return blob.download_as_bytes()