Creative Content Generation with Gemini in Vertex AI and Imagen
Source notebook
Repo path:
gemini/use-cases/marketing/creative_content_generation.ipynb· Open on GitHub · intermediate
Generates and personalizes GShoe marketing copy with Gemini, then outpaints product images with Imagen.
Summary
This notebook teaches a marketing workflow that starts with Gemini text generation from a product name, then improves prompts with a product description and product image. It demonstrates targeting posts for social platforms, adapting copy for professions, generations, countries, and languages, then using Imagen outpainting to expand a product image from 1:1 to 16:9.
Key code patterns
Initialize Vertex AI
import vertexai
PROJECT_ID = "YOUR_PROJECT_ID"
REGION = "us-central1"
vertexai.init(project=PROJECT_ID, location=REGION)Sets the project and region required before using Vertex AI models.
Generate copy with Gemini
from vertexai.generative_models import GenerativeModel
model = GenerativeModel("gemini-2.0-flash")
prompt = f"""
Generate a few social media posts about {product_name}.
This is the product description: {product_description}
"""
response = model.generate_content(prompt).textShows iterative prompt enrichment from product name to detailed marketing context.
Use product image input
from vertexai.generative_models import Part
product_image = Part.from_uri(
"gs://github-repo/use-cases/marketing/gshoe-images/gshoe-01.jpg",
mime_type="image/jpeg",
)
content = [prompt, product_image]
posts = model.generate_content(content).textUses Gemini multimodal input to ground social posts in a product image.
Personalize existing posts
prompt = f"""
Reference to these social media posts: \n{social_media_posts}
Make the posts suitable for students
"""
result = model.generate_content(prompt).textReuses generated copy as context for audience-specific adaptation.
Outpaint with Imagen
from vertexai.preview.vision_models import Image, ImageGenerationModel
imagen_model = ImageGenerationModel.from_pretrained("imagegeneration@006")
base_img = Image.load_from_file(location=image_path)
mask_img = Image.load_from_file(location=mask_path)
images = imagen_model.edit_image(
base_image=base_img,
mask=mask_img,
edit_mode="outpainting",
prompt="a shoe surround by flowers",
)Expands a prepared product image and mask using Imagen outpainting.
Models & APIs used
- Models: gemini-2.0-flash,
imagegeneration@006 - APIs / services: Vertex AI, Gemini API in Vertex AI, Imagen on Vertex AI, Cloud Storage
- SDKs / libraries:
google-cloud-aiplatform,vertexai,requests,PIL
When to use this
Use this pattern to prototype marketing content generation and platform-specific creative assets from product text and imagery.
Gotchas & caveats
- Requires an existing Google Cloud project with billing enabled.
- Vertex AI API must be enabled.
- Local execution requires Cloud SDK installation.
- Colab requires explicit Google Cloud authentication; Vertex AI Workbench does not.
- Notebook was tested with Python 3.11 and google-cloud-aiplatform 1.54.0.
- Imagen features in the sample require allowlisting through the Imagen on Vertex AI access request form.
- The outpainting helper expects a 1:1 input image and raises an error otherwise.
- The sample uses us-central1 unless REGION is changed.
Best practices
- Add product description to improve generated output quality.
- Use product images as multimodal context for marketing messages.
- Target generated posts to specific platforms such as Facebook, Instagram, LinkedIn, and Twitter.
- Reuse generated posts as reference context when personalizing for audience segments.
- Prepare an expanded base image and mask before calling Imagen outpainting.
- Clean up by deleting projects or resources and disabling the Vertex AI API to avoid charges.
Related
- Concepts: Gemini Capabilities · Vision · Applied Use Cases
- Entities: Vertex AI · Vertex AI SDK · Cloud Storage · Imagen · Gemini
- Area: Gemini Notebooks
- Best practices: Gemini Capabilities - Best Practices · Vision - Best Practices · Applied Use Cases - Best Practices