sunholo 0.71.27__py3-none-any.whl → 0.71.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sunholo/gcs/__init__.py CHANGED
@@ -1 +1 @@
1
- from .download_url import construct_download_link
1
+ from .download_url import construct_download_link, get_bytes_from_gcs, get_image_from_gcs
@@ -14,12 +14,67 @@ except ImportError:
14
14
 
15
15
  from ..logging import log
16
16
  from ..utils.gcp import is_running_on_gcp
17
+ from io import BytesIO
18
+ try:
19
+ from PIL import Image
20
+ except ImportError:
21
+ Image = None
17
22
 
18
23
  gcs_credentials = None
19
24
  project_id = None
20
25
  gcs_client = None
21
26
  gcs_bucket_cache = {}
22
27
 
28
+ def get_image_from_gcs(gs_uri: str):
29
+ """Converts image bytes from GCS to a PIL Image object."""
30
+ image_bytes = get_bytes_from_gcs(gs_uri)
31
+ if not Image:
32
+ raise ImportError('Could not import PIL (pillow) - install via `pip install sunholo[gcp]`')
33
+ try:
34
+ img = Image.open(BytesIO(image_bytes))
35
+ return img
36
+ except IOError as e:
37
+ raise ValueError("Unable to open image from bytes:", e)
38
+
39
+ def get_bytes_from_gcs(gs_uri):
40
+ """
41
+ Downloads a file from Google Cloud Storage and returns its bytes.
42
+
43
+ Args:
44
+ gs_uri (str): The Google Cloud Storage URI of the file to download (e.g., 'gs://bucket_name/file_name').
45
+
46
+ Returns:
47
+ bytes: The content of the file in bytes, or None if an error occurs.
48
+ """
49
+ if not gs_uri.startswith('gs://'):
50
+ log.error(f"Invalid GCS URI: {gs_uri}")
51
+ return None
52
+
53
+ try:
54
+ storage_client = storage.Client()
55
+ except Exception as err:
56
+ log.error(f"Error creating storage client: {str(err)}")
57
+ return None
58
+
59
+ try:
60
+ # Parse the GCS URI
61
+ path_parts = gs_uri[5:].split('/', 1)
62
+ bucket_name = path_parts[0]
63
+ blob_name = path_parts[1]
64
+
65
+ # Get the bucket and blob
66
+ bucket = storage_client.bucket(bucket_name)
67
+ blob = bucket.blob(blob_name)
68
+
69
+ # Download the blob as bytes
70
+ file_bytes = blob.download_as_bytes()
71
+ return file_bytes
72
+
73
+ except Exception as err:
74
+ log.error(f"Error downloading file from GCS: {str(err)}")
75
+ return None
76
+
77
+
23
78
  if is_running_on_gcp():
24
79
  # Perform a refresh request to get the access token of the current credentials (Else, it's None)
25
80
  gcs_credentials, project_id = google.auth.default()
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.71.27
3
+ Version: 0.71.29
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Home-page: https://github.com/sunholo-data/sunholo-py
6
- Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.71.27.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.71.29.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -56,6 +56,7 @@ Requires-Dist: langchain-anthropic >=0.1.13 ; extra == 'all'
56
56
  Requires-Dist: langfuse ; extra == 'all'
57
57
  Requires-Dist: pg8000 ; extra == 'all'
58
58
  Requires-Dist: pgvector ; extra == 'all'
59
+ Requires-Dist: pillow ; extra == 'all'
59
60
  Requires-Dist: playwright ; extra == 'all'
60
61
  Requires-Dist: psycopg2-binary ; extra == 'all'
61
62
  Requires-Dist: pypdf ; extra == 'all'
@@ -82,6 +83,8 @@ Requires-Dist: psycopg2-binary ; extra == 'database'
82
83
  Requires-Dist: lancedb ; extra == 'database'
83
84
  Requires-Dist: tantivy ; extra == 'database'
84
85
  Provides-Extra: gcp
86
+ Requires-Dist: google-api-python-client ; extra == 'gcp'
87
+ Requires-Dist: google-cloud-alloydb-connector[pg8000] ; extra == 'gcp'
85
88
  Requires-Dist: google-auth-httplib2 ; extra == 'gcp'
86
89
  Requires-Dist: google-auth-oauthlib ; extra == 'gcp'
87
90
  Requires-Dist: google-cloud-aiplatform ; extra == 'gcp'
@@ -95,8 +98,7 @@ Requires-Dist: google-cloud-discoveryengine ; extra == 'gcp'
95
98
  Requires-Dist: google-generativeai >=0.7.1 ; extra == 'gcp'
96
99
  Requires-Dist: langchain-google-genai >=1.0.5 ; extra == 'gcp'
97
100
  Requires-Dist: langchain-google-alloydb-pg >=0.2.2 ; extra == 'gcp'
98
- Requires-Dist: google-api-python-client ; extra == 'gcp'
99
- Requires-Dist: google-cloud-alloydb-connector[pg8000] ; extra == 'gcp'
101
+ Requires-Dist: pillow ; extra == 'gcp'
100
102
  Provides-Extra: http
101
103
  Requires-Dist: fastapi ; extra == 'http'
102
104
  Requires-Dist: flask ; extra == 'http'
@@ -66,9 +66,9 @@ sunholo/discovery_engine/create_new.py,sha256=7oZG78T6lW0EspRzlo7-qRyXFSuFxDn2df
66
66
  sunholo/discovery_engine/discovery_engine_client.py,sha256=YYsFeaW41l8jmWCruQnYxJGKEYBZ7dduTBDhdxI63hQ,17719
67
67
  sunholo/embedder/__init__.py,sha256=sI4N_CqgEVcrMDxXgxKp1FsfsB4FpjoXgPGkl4N_u4I,44
68
68
  sunholo/embedder/embed_chunk.py,sha256=d_dIzeNF630Q0Ar-u1hxos60s0tLIImJccAvuo_LTIw,6814
69
- sunholo/gcs/__init__.py,sha256=DtVw_AZwQn-IguR5BJuIi2XJeF_FQXizhJikzRNrXiE,50
69
+ sunholo/gcs/__init__.py,sha256=SZvbsMFDko40sIRHTHppA37IijvJTae54vrhooEF5-4,90
70
70
  sunholo/gcs/add_file.py,sha256=Nj75z1MH9fp3fvwd1BVLcHNFm0CVCR2uS4uByThos-o,6924
71
- sunholo/gcs/download_url.py,sha256=8XSEf8byfubqs5CMQeF_tn9wxqwUTq3n9mo5mLNIUTA,4801
71
+ sunholo/gcs/download_url.py,sha256=Kg9EdPnc---YSUTAZEdzJeITjDtQSLMYwb4uiU9LhIQ,6440
72
72
  sunholo/gcs/metadata.py,sha256=C9sMPsHsq1ETetdQCqB3EBs3Kws8b8QHS9L7ei_v5aw,891
73
73
  sunholo/langfuse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  sunholo/langfuse/callback.py,sha256=CTaos8sYcrga949BG6lIZ4I62DiiQSHxwz5re9XjDWQ,1677
@@ -115,9 +115,9 @@ sunholo/vertex/extensions_class.py,sha256=E0ix4YqFQG9EglKeTmp2-zwuZUA2crileGahAh
115
115
  sunholo/vertex/init.py,sha256=-w7b9GKsyJnAJpYHYz6_zBUtmeJeLXlEkgOfwoe4DEI,2715
116
116
  sunholo/vertex/memory_tools.py,sha256=WpedE5yDZcQiFOFBSOtwr-tRCnCXW9G6aZ01rFDfsMo,6862
117
117
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
118
- sunholo-0.71.27.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
119
- sunholo-0.71.27.dist-info/METADATA,sha256=xIbZuxm2LoY9GSE8yn5L1DLNOjX2D2F577PP4JiC3vE,6767
120
- sunholo-0.71.27.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
121
- sunholo-0.71.27.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
122
- sunholo-0.71.27.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
123
- sunholo-0.71.27.dist-info/RECORD,,
118
+ sunholo-0.71.29.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
119
+ sunholo-0.71.29.dist-info/METADATA,sha256=d6FfqsjFFquwLAd3WvMfS7WSiaYDEhB8oamqx1gpFpU,6845
120
+ sunholo-0.71.29.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
121
+ sunholo-0.71.29.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
122
+ sunholo-0.71.29.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
123
+ sunholo-0.71.29.dist-info/RECORD,,