Skip to content

Compare Job Example#

To learn about the basics of creating a job, please refer to the quickstart guide.

In this example, we compare images from two image generation models (Flux and Midjourney) to determine which more accurately follows the given prompts.

from rapidata import RapidataClient

PROMPTS = [
    "A sign that says 'Diffusion'.",
    "A yellow flower sticking out of a green pot.",
    "hyperrealism render of a surreal alien humanoid.",
    "psychedelic duck",
    "A small blue book sitting on a large red book."
]

IMAGE_PAIRS = [
    ["https://assets.rapidata.ai/flux_sign_diffusion.jpg", "https://assets.rapidata.ai/mj_sign_diffusion.jpg"],
    ["https://assets.rapidata.ai/flux_flower.jpg", "https://assets.rapidata.ai/mj_flower.jpg"],
    ["https://assets.rapidata.ai/flux_alien.jpg", "https://assets.rapidata.ai/mj_alien.jpg"],
    ["https://assets.rapidata.ai/flux_duck.jpg", "https://assets.rapidata.ai/mj_duck.jpg"],
    ["https://assets.rapidata.ai/flux_book.jpg", "https://assets.rapidata.ai/mj_book.jpg"]
]

client = RapidataClient()

audience = client.audience.create_audience(name="Prompt Alignment Audience")
audience.add_compare_example(
    instruction="Which image follows the prompt more accurately?",
    datapoint=[
        "https://assets.rapidata.ai/flux_sign_diffusion.jpg",
        "https://assets.rapidata.ai/mj_sign_diffusion.jpg"
    ],
    truth="https://assets.rapidata.ai/flux_sign_diffusion.jpg",
    context="A sign that says 'Diffusion'."
)

job_definition = client.job.create_compare_job_definition(
    name="Example Image Prompt Alignment Job",
    instruction="Which image follows the prompt more accurately?",
    datapoints=IMAGE_PAIRS,
    responses_per_datapoint=25,
    contexts=PROMPTS
)

job_definition.preview()

job = audience.assign_job(job_definition)
job.display_progress_bar()
results = job.get_results()
print(results)