프롬프트 수정 도구 사용

이미지 생성 사용해 보기(Vertex AI Studio)

Colab에서 Imagen 사용해 보기

Vertex AI의 Imagen은 프롬프트 수정 도구라고도 하는 LLM 기반 프롬프트 재작성 도구를 제공합니다. 프롬프트 수정 도구는 프롬프트에 세부정보를 추가하여 더 높은 품질의 출력 이미지를 얻는 데 도움이 됩니다.

프롬프트 수정 도구를 사용 중지하면 이미지 품질과 출력이 제공된 프롬프트와 얼마나 유사한지에 영향을 줄 수 있습니다. 이 기능은 다음 모델 버전에서 기본적으로 사용 설정되어 있습니다.

  • imagen-4.0-generate-001
  • imagen-4.0-fast-generate-001
  • imagen-4.0-ultra-generate-001
  • imagen-3.0-generate-002

수정된 프롬프트는 원래 프롬프트의 길이가 30단어 미만인 경우에만 API 응답을 통해 제공됩니다.

프롬프트 수정 도구 사용

프롬프트 수정 도구를 사용하려면 다음 단계를 따르세요.

콘솔

  1. Google Cloud 콘솔에서 Vertex AI > Media Studio 페이지로 이동합니다.

    Media Studio로 이동

  2. Imagen을 클릭합니다. Imagen Media Studio 이미지 생성 페이지가 표시됩니다.

  3. 설정 패널에서 다음 옵션을 조정합니다.

    • 모델: 사용 가능한 옵션 중에서 모델을 선택합니다.

      사용 가능한 모델에 대한 자세한 내용은 Imagen 모델을 참조하세요.

    • 결과 수: 슬라이더를 조정하거나 1~4 사이의 값을 입력합니다.

    • 부정 프롬프트 상자에 이미지에 생성하지 않으려는 항목을 설명하는 프롬프트를 입력합니다.

  4. 프롬프트 작성 상자에서 글쓰기 도우미를 클릭합니다.

    프롬프트 향상 창이 표시됩니다.

  5. 현재 프롬프트 상자에 프롬프트를 입력한 다음 개선을 클릭합니다.

    재작성된 프롬프트가 향상된 프롬프트 상자에 표시됩니다. 향상된 프롬프트를 수정하거나 표시된 대로 사용할 수 있습니다.

  6. 표시된 프롬프트를 사용하려면 삽입을 클릭합니다.

    프롬프트가 프롬프트 작성 상자에 삽입됩니다.

  7. 생성을 클릭합니다.

REST

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: Google Cloud 프로젝트 ID입니다.
  • MODEL_VERSION: 사용할 이미지 생성 모델 버전입니다.

    모델 버전 및 기능에 대한 자세한 내용은 모델 버전을 참조하세요.

  • LOCATION: 프로젝트의 리전입니다. 예를 들면 us-central1, europe-west2, asia-northeast3입니다. 사용 가능한 리전 목록은 Vertex AI의 생성형 AI 위치를 참조하세요.
  • TEXT_PROMPT: 모델이 생성하는 이미지를 안내하는 텍스트 프롬프트입니다. 이미지가 생성되기 전에 이 기본 프롬프트는 LLM 기반 프롬프트 수정 도구를 사용하여 더 많은 세부정보와 설명적 언어로 개선됩니다.
  • IMAGE_COUNT: 생성할 이미지 수를 설명하는 정수입니다. 허용되는 값은 1~4입니다. 기본값은 4입니다.
  • PROMPT_SETTING: 불리언 값입니다. true는 향상된 프롬프트를 사용 설정하고 false는 향상된 프롬프트를 중지합니다. 기본값은 true입니다.

HTTP 메서드 및 URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict

JSON 요청 본문:

{
  "instances": [
    {
      "prompt": "TEXT_PROMPT"
    }
  ],
  "parameters": {
    "sampleCount": IMAGE_COUNT,
    "enhancePrompt": PROMPT_SETTING
  }
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict" | Select-Object -Expand Content
프롬프트 개선이 사용 설정된 경우 응답에는 향상된 프롬프트와 이와 연결된 생성된 이미지를 보여주는 추가 prompt 필드가 포함됩니다.
  {
    "predictions": [
      {
        "mimeType": "MIME_TYPE",
        "prompt": "ENHANCED_PROMPT_1",
        "bytesBase64Encoded": "BASE64_IMG_BYTES_1"
      },
      {
        "mimeType": "MIME_TYPE",
        "prompt": "ENHANCED_PROMPT_2",
        "bytesBase64Encoded": "BASE64_IMG_BYTES_2"
      }
    ]
  }

예를 들어 다음 샘플 응답은 "sampleCount": 2"prompt": "A raccoon wearing formal clothes, wearing a top hat. Oil painting in the style of Vincent Van Gogh."가 포함된 요청에 대한 응답입니다. 응답은 각기 향상된 프롬프트와 생성된 이미지 바이트를 base64로 인코딩한 두 개의 예측 객체를 반환합니다.

{
  "predictions": [
    {
      "mimeType": "image/png",
      "prompt": "An oil painting in the style of Vincent van Gogh,
        depicting a raccoon adorned in a finely tailored tuxedo, complete with a
        crisp white shirt and a bow tie. The raccoon also sports a classic top
        hat, perched jauntily on its head. The painting uses thick, swirling
        brushstrokes characteristic of van Gogh, with vibrant hues of blue,
        yellow, and green in the background, contrasting with the dark tones of
        the raccoon's attire. The light source is subtly placed, casting a
        dramatic shadow of the raccoon's attire onto the surface it sits upon,
        further enhancing the depth and dimensionality of the composition. The
        overall impression is one of a whimsical and sophisticated character, a
        raccoon elevated to a higher class through its formal attire, rendered
        in van Gogh's iconic style.",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    },
    {
      "mimeType": "image/png",
      "prompt": "An oil painting in the style of Vincent van Gogh featuring
        a raccoon in a dapper suit, complete with a black jacket, crisp white
        shirt, and a black bow tie. The raccoon is wearing a black top hat,
        adding a touch of elegance to its ensemble. The painting is rendered
        with characteristic van Gogh brushwork, utilizing thick, impasto strokes
        of color. The background is a swirl of blues, greens, and yellows,
        creating a vibrant yet slightly chaotic atmosphere that contrasts with
        the raccoon's formal attire. The lighting is dramatic, casting sharp
        shadows and highlighting the textures of the fabric and the raccoon's
        fur, enhancing the sense of realism within the fantastical scene. The
        composition focuses on the raccoon's proud posture, highlighting the
        whimsical contrast of a wild animal dressed in formal attire, captured
        in the unique artistic language of van Gogh. ",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}

다음 단계