Skip to content

Text to Image

Overview

Text To Image component is a quick and simple way of getting started with Mesop. Text To Image is part of Mesop Labs.

Examples

import mesop as me
import mesop.labs as mel


@me.page(
  security_policy=me.SecurityPolicy(
    allowed_iframe_parents=["https://google.github.io"]
  ),
  path="/text_to_image",
  title="Text to Image Example",
)
def app():
  mel.text_to_image(
    generate_image,
    title="Text to Image Example",
  )


def generate_image(prompt: str):
  return "https://www.google.com/logos/doodles/2024/earth-day-2024-6753651837110453-2xa.gif"

API

text_to_image

Creates a simple UI which takes in a text input and returns an image output.

This function creates event handlers for text input and output operations using the provided function transform to process the input and generate the image output.

PARAMETER DESCRIPTION
transform

Function that takes in a string input and returns a URL to an image or a base64 encoded image.

TYPE: Callable[[str], str]

title

Headline text to display at the top of the UI.

TYPE: str | None DEFAULT: None