|
91 | 91 | }, |
92 | 92 | { |
93 | 93 | "cell_type": "code", |
94 | | - "execution_count": 3, |
| 94 | + "execution_count": 9, |
95 | 95 | "metadata": { |
96 | 96 | "colab": { |
97 | 97 | "base_uri": "https://localhost:8080/" |
|
1451 | 1451 | "cell_type": "markdown", |
1452 | 1452 | "metadata": {}, |
1453 | 1453 | "source": [ |
1454 | | - "### 6. Audio transcribe function" |
| 1454 | + "### 6. Audio transcribe" |
1455 | 1455 | ] |
1456 | 1456 | }, |
1457 | 1457 | { |
1458 | 1458 | "cell_type": "code", |
1459 | | - "execution_count": 21, |
| 1459 | + "execution_count": 10, |
1460 | 1460 | "metadata": {}, |
1461 | | - "outputs": [ |
1462 | | - { |
1463 | | - "name": "stderr", |
1464 | | - "output_type": "stream", |
1465 | | - "text": [ |
1466 | | - "/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", |
1467 | | - "instead of using `db_dtypes` in the future when available in pandas\n", |
1468 | | - "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
1469 | | - " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
1470 | | - ] |
1471 | | - } |
1472 | | - ], |
| 1461 | + "outputs": [], |
1473 | 1462 | "source": [ |
1474 | 1463 | "audio_gcs_path = \"gs://bigframes_blob_test/audio/*\"\n", |
1475 | 1464 | "df = bpd.from_glob_path(audio_gcs_path, name=\"audio\")" |
1476 | 1465 | ] |
1477 | 1466 | }, |
1478 | 1467 | { |
1479 | 1468 | "cell_type": "code", |
1480 | | - "execution_count": 22, |
| 1469 | + "execution_count": 11, |
1481 | 1470 | "metadata": {}, |
1482 | 1471 | "outputs": [ |
1483 | 1472 | { |
1484 | 1473 | "name": "stderr", |
1485 | 1474 | "output_type": "stream", |
1486 | 1475 | "text": [ |
1487 | | - "/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", |
1488 | | - "instead of using `db_dtypes` in the future when available in pandas\n", |
1489 | | - "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
1490 | | - " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n", |
1491 | | - "/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", |
| 1476 | + "/usr/local/google/home/shuowei/src/python-bigquery-dataframes/bigframes/dtypes.py:987: JSONDtypeWarning: JSON columns will be represented as pandas.ArrowDtype(pyarrow.json_())\n", |
1492 | 1477 | "instead of using `db_dtypes` in the future when available in pandas\n", |
1493 | 1478 | "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
1494 | 1479 | " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
1495 | 1480 | ] |
1496 | 1481 | }, |
1497 | 1482 | { |
1498 | 1483 | "data": { |
| 1484 | + "text/html": [ |
| 1485 | + "<pre>0 Now, as all books, not primarily intended as p...</pre>" |
| 1486 | + ], |
1499 | 1487 | "text/plain": [ |
1500 | 1488 | "0 Now, as all books, not primarily intended as p...\n", |
1501 | 1489 | "Name: transcribed_content, dtype: string" |
1502 | 1490 | ] |
1503 | 1491 | }, |
1504 | | - "execution_count": 22, |
| 1492 | + "execution_count": 11, |
1505 | 1493 | "metadata": {}, |
1506 | 1494 | "output_type": "execute_result" |
1507 | 1495 | } |
1508 | 1496 | ], |
1509 | 1497 | "source": [ |
1510 | | - "transcribed_series = df['audio'].blob.audio_transcribe(model_name=\"gemini-2.0-flash-001\", verbose=False)\n", |
| 1498 | + "import bigframes.bigquery as bbq\n", |
| 1499 | + "import bigframes.operations as ops\n", |
| 1500 | + "\n", |
| 1501 | + "# The audio_transcribe function is a convenience wrapper around bigframes.bigquery.ai.generate.\n", |
| 1502 | + "# Here's how to perform the same operation directly:\n", |
| 1503 | + "\n", |
| 1504 | + "audio_series = df['audio']\n", |
| 1505 | + "prompt_text = (\n", |
| 1506 | + " \"**Task:** Transcribe the provided audio. **Instructions:** - Your response \"\n", |
| 1507 | + " \"must contain only the verbatim transcription of the audio. - Do not include \"\n", |
| 1508 | + " \"any introductory text, summaries, or conversational filler in your response. \"\n", |
| 1509 | + " \"The output should begin directly with the first word of the audio.\"\n", |
| 1510 | + ")\n", |
| 1511 | + "\n", |
| 1512 | + "# Convert the audio series to the runtime representation required by the model.\n", |
| 1513 | + "# This involves fetching metadata and getting a signed access URL.\n", |
| 1514 | + "audio_metadata = audio_series._apply_unary_op(ops.obj_fetch_metadata_op)\n", |
| 1515 | + "audio_runtime = audio_metadata._apply_unary_op(ops.ObjGetAccessUrl(mode=\"R\"))\n", |
| 1516 | + "\n", |
| 1517 | + "transcribed_results = bbq.ai.generate(\n", |
| 1518 | + " prompt=(prompt_text, audio_runtime),\n", |
| 1519 | + " endpoint=\"gemini-2.0-flash-001\",\n", |
| 1520 | + " model_params={\"generationConfig\": {\"temperature\": 0.0}},\n", |
| 1521 | + ")\n", |
| 1522 | + "\n", |
| 1523 | + "transcribed_series = transcribed_results.struct.field(\"result\").rename(\"transcribed_content\")\n", |
1511 | 1524 | "transcribed_series" |
1512 | 1525 | ] |
1513 | 1526 | }, |
1514 | 1527 | { |
1515 | 1528 | "cell_type": "code", |
1516 | | - "execution_count": 23, |
| 1529 | + "execution_count": 12, |
1517 | 1530 | "metadata": {}, |
1518 | 1531 | "outputs": [ |
1519 | | - { |
1520 | | - "name": "stderr", |
1521 | | - "output_type": "stream", |
1522 | | - "text": [ |
1523 | | - "/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", |
1524 | | - "instead of using `db_dtypes` in the future when available in pandas\n", |
1525 | | - "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
1526 | | - " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n", |
1527 | | - "/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", |
1528 | | - "instead of using `db_dtypes` in the future when available in pandas\n", |
1529 | | - "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
1530 | | - " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
1531 | | - ] |
1532 | | - }, |
1533 | 1532 | { |
1534 | 1533 | "data": { |
| 1534 | + "text/html": [ |
| 1535 | + "<pre>0 {'status': '', 'content': 'Now, as all books, ...</pre>" |
| 1536 | + ], |
1535 | 1537 | "text/plain": [ |
1536 | 1538 | "0 {'status': '', 'content': 'Now, as all books, ...\n", |
1537 | 1539 | "Name: transcription_results, dtype: struct<status: string, content: string>[pyarrow]" |
1538 | 1540 | ] |
1539 | 1541 | }, |
1540 | | - "execution_count": 23, |
| 1542 | + "execution_count": 12, |
1541 | 1543 | "metadata": {}, |
1542 | 1544 | "output_type": "execute_result" |
1543 | 1545 | } |
1544 | 1546 | ], |
1545 | 1547 | "source": [ |
1546 | | - "transcribed_series_verbose = df['audio'].blob.audio_transcribe(model_name=\"gemini-2.0-flash-001\", verbose=True)\n", |
| 1548 | + "# To get verbose results (including status), we can extract both fields from the result struct.\n", |
| 1549 | + "transcribed_content_series = transcribed_results.struct.field(\"result\")\n", |
| 1550 | + "transcribed_status_series = transcribed_results.struct.field(\"status\")\n", |
| 1551 | + "\n", |
| 1552 | + "transcribed_series_verbose = bpd.DataFrame(\n", |
| 1553 | + " {\n", |
| 1554 | + " \"status\": transcribed_status_series,\n", |
| 1555 | + " \"content\": transcribed_content_series,\n", |
| 1556 | + " }\n", |
| 1557 | + ")\n", |
| 1558 | + "# Package as a struct for consistent display\n", |
| 1559 | + "transcribed_series_verbose = bbq.struct(transcribed_series_verbose).rename(\"transcription_results\")\n", |
1547 | 1560 | "transcribed_series_verbose" |
1548 | 1561 | ] |
1549 | 1562 | } |
|
1567 | 1580 | "name": "python", |
1568 | 1581 | "nbconvert_exporter": "python", |
1569 | 1582 | "pygments_lexer": "ipython3", |
1570 | | - "version": "3.10.18" |
| 1583 | + "version": "3.13.0" |
1571 | 1584 | } |
1572 | 1585 | }, |
1573 | 1586 | "nbformat": 4, |
|
0 commit comments