Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit e36dd8b

Browse filesBrowse files
authored
docs: Update multimodal notebook to use public runtime helpers (#2451)
This PR updates notebooks/multimodal/multimodal_dataframe.ipynb to use public APIs (bigframes.bigquery.obj and bigframes.bigquery.to_json_string) instead of internal operations for retrieving runtime JSON strings. Fixes #<issue_number_goes_here> 🦕
1 parent 61c17e3 commit e36dd8b
Copy full SHA for e36dd8b

1 file changed

+41-37Lines changed: 41 additions & 37 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎notebooks/multimodal/multimodal_dataframe.ipynb‎

Copy file name to clipboardExpand all lines: notebooks/multimodal/multimodal_dataframe.ipynb
+41-37Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 9,
95+
"execution_count": 1,
9696
"metadata": {
9797
"colab": {
9898
"base_uri": "https://localhost:8080/"
@@ -128,6 +128,38 @@
128128
"import bigframes.bigquery as bbq"
129129
]
130130
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": 2,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"import bigframes.bigquery as bbq\n",
138+
"\n",
139+
"def get_runtime_json_str(series, mode=\"R\", with_metadata=False):\n",
140+
" \"\"\"\n",
141+
" Get the runtime (contains signed URL to access gcs data) and apply the\n",
142+
" ToJSONSTring transformation.\n",
143+
" \n",
144+
" Args:\n",
145+
" series: bigframes.series.Series to operate on.\n",
146+
" mode: \"R\" for read, \"RW\" for read/write.\n",
147+
" with_metadata: Whether to fetch and include blob metadata.\n",
148+
" \"\"\"\n",
149+
" # 1. Optionally fetch metadata\n",
150+
" s = (\n",
151+
" bbq.obj.fetch_metadata(series)\n",
152+
" if with_metadata\n",
153+
" else series\n",
154+
" )\n",
155+
" \n",
156+
" # 2. Retrieve the access URL runtime object\n",
157+
" runtime = bbq.obj.get_access_url(s, mode=mode)\n",
158+
" \n",
159+
" # 3. Convert the runtime object to a JSON string\n",
160+
" return bbq.to_json_string(runtime)"
161+
]
162+
},
131163
{
132164
"cell_type": "markdown",
133165
"metadata": {
@@ -1290,22 +1322,11 @@
12901322
},
12911323
{
12921324
"cell_type": "code",
1293-
"execution_count": 17,
1325+
"execution_count": 3,
12941326
"metadata": {
12951327
"id": "oDDuYtUm5Yiy"
12961328
},
1297-
"outputs": [
1298-
{
1299-
"name": "stderr",
1300-
"output_type": "stream",
1301-
"text": [
1302-
"/usr/local/google/home/shuowei/src/github.com/googleapis/python-bigquery-dataframes/bigframes/dtypes.py:959: JSONDtypeWarning: JSON columns will be represented as pandas.ArrowDtype(pyarrow.json_())\n",
1303-
"instead of using `db_dtypes` in the future when available in pandas\n",
1304-
"(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n",
1305-
" warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n"
1306-
]
1307-
}
1308-
],
1329+
"outputs": [],
13091330
"source": [
13101331
"df_pdf = bpd.from_glob_path(\"gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/documents/*\", name=\"pdf\")"
13111332
]
@@ -1464,7 +1485,7 @@
14641485
},
14651486
{
14661487
"cell_type": "code",
1467-
"execution_count": 10,
1488+
"execution_count": 4,
14681489
"metadata": {},
14691490
"outputs": [],
14701491
"source": [
@@ -1474,7 +1495,7 @@
14741495
},
14751496
{
14761497
"cell_type": "code",
1477-
"execution_count": 11,
1498+
"execution_count": null,
14781499
"metadata": {},
14791500
"outputs": [
14801501
{
@@ -1486,26 +1507,9 @@
14861507
"(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n",
14871508
" warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n"
14881509
]
1489-
},
1490-
{
1491-
"data": {
1492-
"text/html": [
1493-
"<pre>0 Now, as all books, not primarily intended as p...</pre>"
1494-
],
1495-
"text/plain": [
1496-
"0 Now, as all books, not primarily intended as p...\n",
1497-
"Name: transcribed_content, dtype: string"
1498-
]
1499-
},
1500-
"execution_count": 11,
1501-
"metadata": {},
1502-
"output_type": "execute_result"
15031510
}
15041511
],
15051512
"source": [
1506-
"import bigframes.bigquery as bbq\n",
1507-
"import bigframes.operations as ops\n",
1508-
"\n",
15091513
"# The audio_transcribe function is a convenience wrapper around bigframes.bigquery.ai.generate.\n",
15101514
"# Here's how to perform the same operation directly:\n",
15111515
"\n",
@@ -1519,8 +1523,8 @@
15191523
"\n",
15201524
"# Convert the audio series to the runtime representation required by the model.\n",
15211525
"# This involves fetching metadata and getting a signed access URL.\n",
1522-
"audio_metadata = audio_series._apply_unary_op(ops.obj_fetch_metadata_op)\n",
1523-
"audio_runtime = audio_metadata._apply_unary_op(ops.ObjGetAccessUrl(mode=\"R\"))\n",
1526+
"audio_metadata = bbq.obj.fetch_metadata(audio_series)\n",
1527+
"audio_runtime = bbq.obj.get_access_url(audio_metadata, mode=\"R\")\n",
15241528
"\n",
15251529
"transcribed_results = bbq.ai.generate(\n",
15261530
" prompt=(prompt_text, audio_runtime),\n",
@@ -1534,7 +1538,7 @@
15341538
},
15351539
{
15361540
"cell_type": "code",
1537-
"execution_count": 12,
1541+
"execution_count": null,
15381542
"metadata": {},
15391543
"outputs": [
15401544
{
@@ -1638,7 +1642,7 @@
16381642
"\n",
16391643
"# Generate a JSON string containing the runtime information (including signed read URLs)\n",
16401644
"# This allows the UDF to download the images from Google Cloud Storage\n",
1641-
"access_urls = exif_image_df[\"blob_col\"].blob.get_runtime_json_str(mode=\"R\")\n",
1645+
"access_urls = get_runtime_json_str(exif_image_df[\"blob_col\"], mode=\"R\")\n",
16421646
"\n",
16431647
"# Apply the BigQuery Python UDF to the runtime JSON strings\n",
16441648
"# We cast to string to ensure the input matches the UDF's signature\n",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.