-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Gemini PDF Sample & Add Type for
GenerationConfig
(#11390)
* Update gemini samples to use GenerationConfig instead of a dict for type safety. * Add PDF Sample for Gemini Pro Vision 1.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update sample PDF * Fix lint error * Fix test case * Fix test case again --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b24c0d4
commit 89505e9
Showing
7 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
# [START generativeaionvertexai_gemini_pdf] | ||
import vertexai | ||
|
||
from vertexai.generative_models import GenerativeModel, Part | ||
|
||
|
||
def generate_text(project_id: str, location: str) -> str: | ||
# Initialize Vertex AI | ||
vertexai.init(project=project_id, location=location) | ||
# Load the model | ||
vision_model = GenerativeModel("gemini-1.0-pro-vision") | ||
# Generate text | ||
response = vision_model.generate_content( | ||
[ | ||
Part.from_uri( | ||
"gs://cloud-samples-data/vertex-ai/generative-ai/pdf/intake-form.pdf", | ||
mime_type="application/pdf", | ||
), | ||
"Output the text in the PDF", | ||
] | ||
) | ||
print(response) | ||
return response.text | ||
|
||
|
||
# [END generativeaionvertexai_gemini_pdf] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters