Gemini를 사용하여 PDF 파일 요약하기

이 샘플은 Gemini를 사용하여 PDF 파일의 요약을 생성하는 방법을 보여줍니다.

코드 샘플

Python

이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 Vertex AI Python API 참고 문서를 참조하세요.

Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import vertexai
from vertexai.generative_models import GenerativeModel, Part

# TODO (developer): update project id
vertexai.init(project=PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.5-flash-002")

contents = [
    # Text prompt
    "Summarise this file",
    # Example PDF document on Transformers, a neural network architecture.
    Part.from_uri(
        "https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/1706.03762v7.pdf",
        "application/pdf",
    ),
]

response = model.generate_content(contents)
print(response.text)
# Example response:
#     'This paper introduces the Transformer, a new neural network architecture for '
#     'sequence transduction, which uses an attention mechanism to learn global '
#     'dependencies between input and output sequences. The Transformer ...

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.