Image-variation-and-edition

Image variation and edition

This Markdown file can be "evaluated" with the Raku package "Text::CodeProcessing", [AAp2]. Here is a shell command:

file-code-chunks-eval Image-variation-and-edition.md 

Remark: For doing image generations using text prompts see the document Image-generation.md (and its woven version, Image-generation_woven.md.)

Image variation

Here we load the Raku package "WWW::OpenAI", [AAp1]:

use WWW::OpenAI;

Variations of images can be generated with the function openai-variate-image -- see the section "Images" of [OAI2].

Here is a (random mandala) image:

izef_www_openai_dist_resources_randommandala_png

Remark: Below we refer to the image above as "the original image."

Here we generate a few variations of the image above, and get "whole images" in Base64 format:

my @imgResB64 = |openai-variate-image(
        $*CWD ~ '/../resources/RandomMandala.png',
        n => 2,
        size => 'small',
        response-format => 'b64_json',
        format => 'values',
        method => 'tiny');

@imgResB64.map({ '![](data:image/png;base64,' ~ $_ ~ ')' }).join("\n\n")        

Remark: The obtained images are put into the woven document via the output of the code cell, which has the setting results=asis.

The first argument is a prompt used to generate the image(s).

Here are the descriptions of the named arguments (options):

  • n takes a positive integer, for the number of images to be generated

  • size takes the values '1024x1024', '512x512', '256x256', 'large', 'medium', 'small'.

  • response-format takes the values "url" and "b64_json"

  • method takes the values "tiny" and "curl"

Here we generate a few variations of the original mandala image above, get their URLs, and place (embed) the image links using a table:

my @imgRes = |openai-variate-image(
        $*CWD ~ '/../resources/RandomMandala.png',
        response-format => 'url',
        n => 2,
        size => 'small',
        format => 'values',
        method => 'tiny');

@imgRes.map({ '![](' ~ $_ ~ ')' }).join("\n\n")       

Image edition

Editions of images can be generated with the function openai-edit-image -- see the section "Images" of [OAI2].

Here are the descriptions of positional arguments:

  • file is a file name string (a PNG image with RGBA color space)

  • prompt is a prompt tha describes the image edition

Here are the descriptions of the named arguments (options):

  • mask-file a file name of a mask image (can be an empty string or Whatever)

  • n takes a positive integer, for the number of images to be generated

  • size takes the values '1024x1024', '512x512', '256x256', 'large', 'medium', 'small'.

  • response-format takes the values "url" and "b64_json"

  • method takes the values "tiny" and "curl"

Here is a random mandala color (RGBA) image:

izef_www_openai_dist_resources_randommandala2_png

Here we generate a few editions of the colored mandala image above, get their URLs, and place (embed) the image links using a table:

my @imgRes = |openai-edit-image(
        $*CWD ~ '/../resources/RandomMandala2.png',
        'add cosmic background',
        response-format => 'url',
        n => 2,
        size => 'small',
        format => 'values',
        method => 'tiny');

@imgRes.map({ '![](' ~ $_ ~ ')' }).join("\n\n")       

References

Articles

[AA1] Anton Antonov, "Connecting Mathematica and Raku", (2021), RakuForPrediction at WordPress.

Packages

[AAp1] Anton Antonov, WWW::OpenAI Raku package, (2023), GitHub/antononcube.

[AAp2] Anton Antonov, Text::CodeProcessing, (2021), GitHub/antononcube.

[OAI1] OpenAI Platform, OpenAI platform.

[OAI2] OpenAI Platform, OpenAI documentation.

[OAIp1] OpenAI, OpenAI Python Library, (2020), GitHub/openai.

WWW::OpenAI v0.3.20

WWW::OpenAI provides access to the OpenAI playground (https://platform.openai.com).

Authors

  • Anton Antonov

License

Artistic-2.0

Dependencies

HTTP::Tiny:ver<0.2.5+>JSON::Fast:ver<0.17+>MIME::Base64:ver<1.2.3+>:auth<zef:raku-community-modules>Image::Markup::Utilities:ver<0.1.0+>:auth<zef:antononcube>IO::Socket::SSL:ver<0.0.2+>

Provides

  • WWW::OpenAI
  • WWW::OpenAI::Audio
  • WWW::OpenAI::Batches
  • WWW::OpenAI::ChatCompletions
  • WWW::OpenAI::Embeddings
  • WWW::OpenAI::Files
  • WWW::OpenAI::ImageEdits
  • WWW::OpenAI::ImageGenerations
  • WWW::OpenAI::ImageVariations
  • WWW::OpenAI::Models
  • WWW::OpenAI::Moderations
  • WWW::OpenAI::Request
  • WWW::OpenAI::TextCompletions

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.