From 60275782d0269e5552d3b3a57989abc79f18ab7b Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Sat, 29 Jun 2024 15:08:30 -0400 Subject: [PATCH 1/3] Add create_audio and create_text --- samples/files.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/samples/files.py b/samples/files.py index 22777796a..bdc3f99f0 100644 --- a/samples/files.py +++ b/samples/files.py @@ -23,7 +23,7 @@ class UnitTests(absltest.TestCase): def test_files_create(self): - # [START files_create] + # [START files_create_text] myfile = genai.upload_file(media / "poem.txt") print(f"{myfile=}") @@ -32,7 +32,17 @@ def test_files_create(self): [myfile, "\n\n", "Can you add a few more lines to this poem?"] ) print(f"{result.text=}") - # [END files_create] + # [END files_create_text] + + def test_files_create_audio(self): + # [START files_create_audio] + myfile = genai.upload_file(media / 'sample.mp3') + print(f"{myfile=}") + + model = genai.GenerativeModel("gemini-1.5-flash") + result = model.generate_content([myfile, "Describe this audio clip"]) + print(f"{result.text=}") + # [END files_create_audio] def test_files_create_video(self): # [START files_create_video] From d3a63151c8ccb0e1f000a49779cacb132ec45b69 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Sat, 29 Jun 2024 15:12:32 -0400 Subject: [PATCH 2/3] Reformat files --- samples/chat.py | 9 ++++++--- samples/files.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/samples/chat.py b/samples/chat.py index 5958979cc..5089450d9 100644 --- a/samples/chat.py +++ b/samples/chat.py @@ -31,7 +31,7 @@ def test_chat(self): ] ) response = chat.send_message("I have 2 dogs in my house.") - print(response.text) + print(response.text) response = chat.send_message("How many paws are in my house?") print(response.text) # [END chat] @@ -62,11 +62,14 @@ def test_chat_streaming_with_images(self): model = genai.GenerativeModel("gemini-1.5-flash") chat = model.start_chat() - response = chat.send_message("Hello, I'm interested in learning about musical instruments. Can I show you one?", stream=True) + response = chat.send_message( + "Hello, I'm interested in learning about musical instruments. Can I show you one?", + stream=True, + ) for chunk in response: print(chunk.text) # Yes. print("_" * 80) - + organ = genai.upload_file(media / "organ.jpg") response = chat.send_message( ["What family of intruments does this instrument belong to?", organ], stream=True diff --git a/samples/files.py b/samples/files.py index bdc3f99f0..e4397ae17 100644 --- a/samples/files.py +++ b/samples/files.py @@ -36,12 +36,12 @@ def test_files_create(self): def test_files_create_audio(self): # [START files_create_audio] - myfile = genai.upload_file(media / 'sample.mp3') + myfile = genai.upload_file(media / "sample.mp3") print(f"{myfile=}") model = genai.GenerativeModel("gemini-1.5-flash") result = model.generate_content([myfile, "Describe this audio clip"]) - print(f"{result.text=}") + print(f"{result.text=}") # [END files_create_audio] def test_files_create_video(self): From b5134986224b7e12afd99110710f99829a0c2d0f Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 2 Jul 2024 15:56:45 -0700 Subject: [PATCH 3/3] Add files_create_image Change-Id: I4a1935b15ed4107dc85806780f9a4ba8ed047e9a --- samples/files.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/files.py b/samples/files.py index e4397ae17..511c814e2 100644 --- a/samples/files.py +++ b/samples/files.py @@ -22,7 +22,7 @@ class UnitTests(absltest.TestCase): - def test_files_create(self): + def test_files_create_text(self): # [START files_create_text] myfile = genai.upload_file(media / "poem.txt") print(f"{myfile=}") @@ -34,6 +34,18 @@ def test_files_create(self): print(f"{result.text=}") # [END files_create_text] + def test_files_create_image(self): + # [START files_create_image] + myfile = genai.upload_file(media / "Cajun_instruments.jpg") + print(f"{myfile=}") + + model = genai.GenerativeModel("gemini-1.5-flash") + result = model.generate_content( + [myfile, "\n\n", "Can you tell me about the instruments in this photo?"] + ) + print(f"{result.text=}") + # [END files_create_image] + def test_files_create_audio(self): # [START files_create_audio] myfile = genai.upload_file(media / "sample.mp3")