Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions bigframes/operations/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,35 +804,29 @@ def audio_transcribe(
raise ValueError("Must specify the engine, supported value is 'bigquery'.")

import bigframes.bigquery as bbq
import bigframes.ml.llm as llm
import bigframes.pandas as bpd

# col name doesn't matter here. Rename to avoid column name conflicts
audio_series = bigframes.series.Series(self._block)

prompt_text = "**Task:** Transcribe the provided audio. **Instructions:** - Your response must contain only the verbatim transcription of the audio. - Do not include any introductory text, summaries, or conversational filler in your response. The output should begin directly with the first word of the audio."

llm_model = llm.GeminiTextGenerator(
model_name=model_name,
session=self._block.session,
connection_name=connection,
)
# Convert the audio series to the runtime representation required by the model.
audio_runtime = audio_series.blob._get_runtime("R", with_metadata=True)

# transcribe audio using ML.GENERATE_TEXT
transcribed_results = llm_model.predict(
X=audio_series,
prompt=[prompt_text, audio_series],
temperature=0.0,
transcribed_results = bbq.ai.generate(
prompt=(prompt_text, audio_runtime),
connection_id=connection,
endpoint=model_name,
model_params={"generationConfig": {"temperature": 0.0}},
)

transcribed_content_series = cast(
bpd.Series, transcribed_results["ml_generate_text_llm_result"]
).rename("transcribed_content")
transcribed_content_series = transcribed_results.struct.field("result").rename(
"transcribed_content"
)

if verbose:
transcribed_status_series = cast(
bpd.Series, transcribed_results["ml_generate_text_status"]
)
transcribed_status_series = transcribed_results.struct.field("status")
results_df = bpd.DataFrame(
{
"status": transcribed_status_series,
Expand Down
Loading