Skip to content

Commit e4c85ba

Browse files
authored
feat: publish bigframes blob(Multimodal) to preview (#1693)
* feat: publish bigframes blob(Multimodal) to preview * fix * fix * reset df notebook
1 parent 46a9c53 commit e4c85ba

File tree

18 files changed

+238
-348
lines changed

18 files changed

+238
-348
lines changed

bigframes/_config/display_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class DisplayOptions:
3535
max_info_rows: Optional[int] = 200000
3636
memory_usage: bool = True
3737

38+
blob_display: bool = True
39+
blob_display_width: Optional[int] = None
40+
blob_display_height: Optional[int] = None
41+
3842

3943
@contextlib.contextmanager
4044
def pandas_repr(display_options: DisplayOptions):

bigframes/_config/experiment_options.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Optional
1616
import warnings
1717

18+
import bigframes
1819
import bigframes.exceptions as bfe
1920

2021

@@ -26,10 +27,6 @@ class ExperimentOptions:
2627
def __init__(self):
2728
self._semantic_operators: bool = False
2829
self._ai_operators: bool = False
29-
self._blob: bool = False
30-
self._blob_display: bool = True
31-
self._blob_display_width: Optional[int] = None
32-
self._blob_display_height: Optional[int] = None
3330

3431
@property
3532
def semantic_operators(self) -> bool:
@@ -60,41 +57,72 @@ def ai_operators(self, value: bool):
6057

6158
@property
6259
def blob(self) -> bool:
63-
return self._blob
60+
msg = bfe.format_message(
61+
"BigFrames Blob is in preview now. This flag is no longer needed."
62+
)
63+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
64+
return True
6465

6566
@blob.setter
6667
def blob(self, value: bool):
67-
if value is True:
68-
msg = bfe.format_message(
69-
"BigFrames Blob is still under experiments. It may not work and "
70-
"subject to change in the future."
71-
)
72-
warnings.warn(msg, category=bfe.PreviewWarning)
73-
self._blob = value
68+
msg = bfe.format_message(
69+
"BigFrames Blob is in preview now. This flag is no longer needed."
70+
)
71+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
7472

7573
@property
7674
def blob_display(self) -> bool:
7775
"""Whether to display the blob content in notebook DataFrame preview. Default True."""
78-
return self._blob_display
76+
msg = bfe.format_message(
77+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display."
78+
)
79+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
80+
81+
return bigframes.options.display.blob_display
7982

8083
@blob_display.setter
8184
def blob_display(self, value: bool):
82-
self._blob_display = value
85+
msg = bfe.format_message(
86+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display."
87+
)
88+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
89+
90+
bigframes.options.display.blob_display = value
8391

8492
@property
8593
def blob_display_width(self) -> Optional[int]:
8694
"""Width in pixels that the blob constrained to."""
87-
return self._blob_display_width
95+
msg = bfe.format_message(
96+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display_width."
97+
)
98+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
99+
100+
return bigframes.options.display.blob_display_width
88101

89102
@blob_display_width.setter
90103
def blob_display_width(self, value: Optional[int]):
91-
self._blob_display_width = value
104+
msg = bfe.format_message(
105+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display_width."
106+
)
107+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
108+
109+
bigframes.options.display.blob_display_width = value
92110

93111
@property
94112
def blob_display_height(self) -> Optional[int]:
95113
"""Height in pixels that the blob constrained to."""
96-
return self._blob_display_height
114+
msg = bfe.format_message(
115+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display_height."
116+
)
117+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
118+
119+
return bigframes.options.display.blob_display_height
97120

98121
@blob_display_height.setter
99122
def blob_display_height(self, value: Optional[int]):
100-
self._blob_display_height = value
123+
msg = bfe.format_message(
124+
"BigFrames Blob is in preview now. The option has been moved to bigframes.options.display.blob_display_height."
125+
)
126+
warnings.warn(msg, category=bfe.ApiDeprecationWarning)
127+
128+
bigframes.options.display.blob_display_height = value

bigframes/dataframe.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,11 @@ def _repr_html_(self) -> str:
768768
return formatter.repr_query_job(self._compute_dry_run())
769769

770770
df = self.copy()
771-
if (
772-
bigframes.options.experiments.blob
773-
and bigframes.options.experiments.blob_display
774-
):
771+
if bigframes.options.display.blob_display:
775772
blob_cols = [
776-
col
777-
for col in df.columns
778-
if df[col].dtype == bigframes.dtypes.OBJ_REF_DTYPE
773+
series_name
774+
for series_name, series in df.items()
775+
if series.dtype == bigframes.dtypes.OBJ_REF_DTYPE
779776
]
780777
for col in blob_cols:
781778
# TODO(garrettwu): Not necessary to get access urls for all the rows. Update when having a to get URLs from local data.
@@ -794,10 +791,7 @@ def _repr_html_(self) -> str:
794791

795792
with display_options.pandas_repr(opts):
796793
# Allows to preview images in the DataFrame. The implementation changes the string repr as well, that it doesn't truncate strings or escape html charaters such as "<" and ">". We may need to implement a full-fledged repr module to better support types not in pandas.
797-
if (
798-
bigframes.options.experiments.blob
799-
and bigframes.options.experiments.blob_display
800-
):
794+
if bigframes.options.display.blob_display and blob_cols:
801795

802796
def obj_ref_rt_to_html(obj_ref_rt) -> str:
803797
obj_ref_rt_json = json.loads(obj_ref_rt)
@@ -809,12 +803,12 @@ def obj_ref_rt_to_html(obj_ref_rt) -> str:
809803
)
810804
if content_type.startswith("image"):
811805
size_str = ""
812-
if bigframes.options.experiments.blob_display_width:
813-
size_str = f' width="{bigframes.options.experiments.blob_display_width}"'
814-
if bigframes.options.experiments.blob_display_height:
806+
if bigframes.options.display.blob_display_width:
807+
size_str = f' width="{bigframes.options.display.blob_display_width}"'
808+
if bigframes.options.display.blob_display_height:
815809
size_str = (
816810
size_str
817-
+ f' height="{bigframes.options.experiments.blob_display_height}"'
811+
+ f' height="{bigframes.options.display.blob_display_height}"'
818812
)
819813
url = obj_ref_rt_json["access_urls"]["read_url"]
820814
return f'<img src="{url}"{size_str}>'

bigframes/ml/llm.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ class MultimodalEmbeddingGenerator(base.RetriableRemotePredictor):
250250
"""Multimodal embedding generator LLM model.
251251
252252
.. note::
253-
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
253+
BigFrames Blob is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
254+
Service Specific Terms(https://cloud.google.com/terms/service-terms#1). Pre-GA products and features are available "as is"
255+
and might have limited support. For more information, see the launch stage descriptions
256+
(https://cloud.google.com/products#product-launch-stages).
254257
255258
Args:
256259
model_name (str, Default to "multimodalembedding@001"):
@@ -271,8 +274,6 @@ def __init__(
271274
session: Optional[bigframes.Session] = None,
272275
connection_name: Optional[str] = None,
273276
):
274-
if not bigframes.options.experiments.blob:
275-
raise NotImplementedError()
276277
if model_name is None:
277278
model_name = "multimodalembedding@001"
278279
msg = exceptions.format_message(_REMOVE_DEFAULT_MODEL_WARNING)
@@ -610,7 +611,10 @@ def predict(
610611
611612
prompt (Iterable of str or bigframes.series.Series, or None, default None):
612613
.. note::
613-
BigFrames Blob is still under experiments. It may not work and subject to change in the future.
614+
BigFrames Blob is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
615+
Service Specific Terms(https://cloud.google.com/terms/service-terms#1). Pre-GA products and features are available "as is"
616+
and might have limited support. For more information, see the launch stage descriptions
617+
(https://cloud.google.com/products#product-launch-stages).
614618
615619
Construct a prompt struct column for prediction based on the input. The input must be an Iterable that can take string literals,
616620
such as "summarize", string column(s) of X, such as X["str_col"], or blob column(s) of X, such as X["blob_col"].
@@ -646,9 +650,6 @@ def predict(
646650
(X,) = utils.batch_convert_to_dataframe(X, session=session)
647651

648652
if prompt:
649-
if not bigframes.options.experiments.blob:
650-
raise NotImplementedError()
651-
652653
if self.model_name not in _GEMINI_MULTIMODAL_ENDPOINTS:
653654
raise NotImplementedError(
654655
f"GeminiTextGenerator only supports model_name {', '.join(_GEMINI_MULTIMODAL_ENDPOINTS)} for Multimodal prompt."

0 commit comments

Comments
 (0)