Skip to content

Commit aa2a88f

Browse files
Add create_audio and create_text to samples/files.py (#414)
* Add create_audio and create_text * Reformat files * Add files_create_image Change-Id: I4a1935b15ed4107dc85806780f9a4ba8ed047e9a --------- Co-authored-by: Mark Daoust <[email protected]>
1 parent 23ce3bd commit aa2a88f

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

samples/files.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
class UnitTests(absltest.TestCase):
25-
def test_files_create(self):
26-
# [START files_create]
25+
def test_files_create_text(self):
26+
# [START files_create_text]
2727
myfile = genai.upload_file(media / "poem.txt")
2828
print(f"{myfile=}")
2929

@@ -32,7 +32,29 @@ def test_files_create(self):
3232
[myfile, "\n\n", "Can you add a few more lines to this poem?"]
3333
)
3434
print(f"{result.text=}")
35-
# [END files_create]
35+
# [END files_create_text]
36+
37+
def test_files_create_image(self):
38+
# [START files_create_image]
39+
myfile = genai.upload_file(media / "Cajun_instruments.jpg")
40+
print(f"{myfile=}")
41+
42+
model = genai.GenerativeModel("gemini-1.5-flash")
43+
result = model.generate_content(
44+
[myfile, "\n\n", "Can you tell me about the instruments in this photo?"]
45+
)
46+
print(f"{result.text=}")
47+
# [END files_create_image]
48+
49+
def test_files_create_audio(self):
50+
# [START files_create_audio]
51+
myfile = genai.upload_file(media / "sample.mp3")
52+
print(f"{myfile=}")
53+
54+
model = genai.GenerativeModel("gemini-1.5-flash")
55+
result = model.generate_content([myfile, "Describe this audio clip"])
56+
print(f"{result.text=}")
57+
# [END files_create_audio]
3658

3759
def test_files_create_video(self):
3860
# [START files_create_video]

0 commit comments

Comments
 (0)