Skip to content

Commit e344f27

Browse files
feat: add 2 more textgen samples to the batch
1 parent 78b7faf commit e344f27

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

genai/text_generation/test_text_generation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
17+
import textgen_transcript_with_gcs_audio
18+
import textgen_with_gcs_audio
1519
import textgen_with_multi_img
1620
import textgen_with_multi_local_img
1721
import textgen_with_mute_video
1822
import textgen_with_video
1923

2024

25+
os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "True"
26+
os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1"
27+
# The project name is included in the CICD pipeline
28+
# os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name"
29+
30+
2131
def test_textgen_with_multi_img() -> None:
2232
response = textgen_with_multi_img.generate_content()
2333
assert response
@@ -36,3 +46,13 @@ def test_textgen_with_mute_video() -> None:
3646
def test_textgen_with_video() -> None:
3747
response = textgen_with_video.generate_content()
3848
assert response
49+
50+
51+
def test_textgen_with_gcs_audio() -> None:
52+
response = textgen_with_gcs_audio.generate_content()
53+
assert response
54+
55+
56+
def test_textgen_transcript_with_gcs_audio() -> None:
57+
response = textgen_transcript_with_gcs_audio.generate_content()
58+
assert response
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def generate_content() -> str:
17+
# [START googlegenaisdk_textgen_transcript_with_gcs_audio]
18+
from google import genai
19+
from google.genai.types import Part
20+
21+
client = genai.Client()
22+
23+
prompt = """
24+
Transcribe the interview, in the format of timecode, speaker, caption.
25+
Use speaker A, speaker B, etc. to identify speakers.
26+
"""
27+
response = client.models.generate_content(
28+
model="gemini-2.0-flash-001",
29+
contents=[
30+
prompt,
31+
Part.from_uri(
32+
"gs://cloud-samples-data/generative-ai/audio/pixel.mp3",
33+
mime_type="audio/mpeg"
34+
)
35+
]
36+
)
37+
print(response.text)
38+
# Example response:
39+
# [00:00:00] **Speaker A:** your devices are getting better over time. And so ...
40+
# [00:00:14] **Speaker B:** Welcome to the Made by Google podcast where we meet ...
41+
# [00:00:20] **Speaker B:** Here's your host, Rasheed Finch.
42+
# [00:00:23] **Speaker C:** Today we're talking to Aisha Sharif and DeCarlos Love. ...
43+
# ...
44+
# [END googlegenaisdk_textgen_transcript_with_gcs_audio]
45+
return response.text
46+
47+
48+
if __name__ == "__main__":
49+
generate_content()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def generate_content() -> str:
17+
# [START googlegenaisdk_textgen_with_gcs_audio]
18+
from google import genai
19+
from google.genai.types import Part
20+
21+
client = genai.Client()
22+
23+
prompt = """
24+
Provide the summary of the audio file.
25+
Summarize the main points of the audio concisely.
26+
Create a chapter breakdown with timestamps for key sections or topics discussed.
27+
"""
28+
response = client.models.generate_content(
29+
model="gemini-2.0-flash-001",
30+
contents=[
31+
prompt,
32+
Part.from_uri(
33+
"gs://cloud-samples-data/generative-ai/audio/pixel.mp3",
34+
mime_type="audio/mpeg"
35+
)
36+
]
37+
)
38+
print(response.text)
39+
# Example response:
40+
# This episode of the Made by Google podcast features product managers ...
41+
#
42+
# **Chapter Breakdown:**
43+
#
44+
# * **[0:00-1:14] Introduction:** Host Rasheed Finch introduces Aisha and DeCarlos and ...
45+
# * **[1:15-2:44] Transformative Features:** Aisha and DeCarlos discuss their ...
46+
# ...
47+
# [END googlegenaisdk_textgen_with_gcs_audio]
48+
return response.text
49+
50+
51+
if __name__ == "__main__":
52+
generate_content()

0 commit comments

Comments
 (0)