Slide Generation with Gemini and Marp

Source notebook

Repo path: gemini/use-cases/productivity/slide_generation_with_marp.ipynb · Open on GitHub · intermediate

Uses Gemini and Marp to turn a blog post into a Markdown slide deck and PDF.

Summary

This notebook teaches how to use the Google Gen AI SDK with Gemini on Vertex AI to generate a Marp-compatible slide deck from a blog post. It loads the Marp repository with Gitingest, sends that context plus a DeepMind blog URL to Gemini, extracts the returned Markdown, writes it to a file, and converts it to PDF with Marp CLI.

Key code patterns

Create Vertex AI GenAI client

from google import genai
 
client = genai.Client(
    vertexai=True,
    project=PROJECT_ID,
    location=LOCATION,
)

Connects the Google Gen AI SDK to Gemini through Vertex AI.

Ingest reference repository

from gitingest import ingest
 
repo_dir = "https://github.com/marp-team/marp"
summary, tree, content = ingest(source=repo_dir, branch="main")

Loads the Marp codebase as prompt context for style and formatting guidance.

Generate Markdown deck

response = client.models.generate_content(
    model=MODEL_ID,
    contents=[content, PROMPT, Part.from_uri(file_uri=blog_url, mime_type="text/html")],
    config=GenerateContentConfig(system_instruction="Only output markdown.", max_output_tokens=8192),
)

Combines repository context, instructions, and a webpage URI to generate slide Markdown.

Extract and render Marp output

marp_text = re.findall(r"```(?:\w*\n)?(.*?)```", response.text + "\n```", re.DOTALL)[0]
 
with open("slide-deck.md", "w") as f:
    f.write(marp_text)
 
!npx @marp-team/marp-cli@latest slide-deck.md --pdf

Parses fenced Markdown from Gemini and converts it into a PDF slide deck.

Models & APIs used

  • Models: gemini-3.5-flash
  • APIs / services: Vertex AI, Gemini API
  • SDKs / libraries: google-genai, gitingest

When to use this

Use this pattern when generating a presentation from web content while giving Gemini reference code or style context.

Gotchas & caveats

  • Requires an existing Google Cloud project with the Vertex AI API enabled.
  • Colab authentication is only needed when running in Google Colab.
  • LOCATION defaults to us-central1 from GOOGLE_CLOUD_REGION when unset.
  • PDF conversion with Marp CLI requires a machine with a web browser installed and is not supported in Colab.
  • The notebook extracts the first fenced code block from the model response, so the response must contain the Markdown deck in fences.

Best practices

  • Use PROJECT_ID from GOOGLE_CLOUD_PROJECT when the placeholder is not replaced.
  • Set a system instruction to restrict Gemini output to Markdown.
  • Provide the Marp repository as context so generated slides can follow Marp style and formatting.
  • Use max_output_tokens=8192 to allow enough room for a complete slide deck.
  • Write generated Markdown to slide-deck.md before rendering it with Marp CLI.