Packages
ai_replace_prompt
1770195.248.27
Professional Elixir integration for ai-replace-prompt. Provides utilities for building links and integrating with https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/.
Current section
Files
Jump to
Current section
Files
lib/ai_replace_prompt.ex
defmodule AiReplacePrompt do
@moduledoc """
Utility functions for generating AI image replacement prompts based on Supermaker.ai's blog.
"""
@base_url "https://supermaker.ai/api"
@doc """
Builds a URL by appending optional parameters to a base URL.
## Examples
iex> AiReplacePrompt.build_url("/images", [size: "small", format: "jpeg"])
"https://supermaker.ai/api/images?size=small&format=jpeg"
iex> AiReplacePrompt.build_url("/users")
"https://supermaker.ai/api/users"
"""
def build_url(path, params \\ []) when is_list(params) do
url = @base_url <> path
case params do
[] -> url
_ ->
query_string =
params
|> Enum.map(fn {key, value} -> "#{key}=#{value}" end)
|> Enum.join("&")
"#{url}?#{query_string}"
end
end
@doc """
Generates a prompt for replacing an object in an image.
## Examples
iex> AiReplacePrompt.generate_replace_prompt("dog", "cat", "realistic")
"Replace the dog with a cat, in a realistic style."
iex> AiReplacePrompt.generate_replace_prompt("sky", "sunset")
"Replace the sky with a sunset, in a style."
"""
def generate_replace_prompt(object_to_replace, replacement_object, style \\ "") when is_binary(object_to_replace) and is_binary(replacement_object) and is_binary(style) do
style_string =
case style do
"" -> ""
_ -> ", in a #{style} style"
end
"Replace the #{object_to_replace} with a #{replacement_object}#{style_string}."
end
@doc """
Creates a prompt specifically for changing the background of an image.
## Examples
iex> AiReplacePrompt.generate_background_prompt("beach")
"Replace the background with a beach."
iex> AiReplacePrompt.generate_background_prompt("mountain landscape", "photorealistic")
"Replace the background with a mountain landscape, in a photorealistic style."
"""
def generate_background_prompt(new_background, style \\ "") when is_binary(new_background) and is_binary(style) do
style_string =
case style do
"" -> ""
_ -> ", in a #{style} style"
end
"Replace the background with a #{new_background}#{style_string}."
end
@doc """
Generates a prompt to add an object to an image.
## Examples
iex> AiReplacePrompt.generate_add_prompt("a cat", "sitting on a chair")
"Add a cat sitting on a chair to the image."
iex> AiReplacePrompt.generate_add_prompt("a UFO", "hovering over a field", "sci-fi")
"Add a UFO hovering over a field to the image, in a sci-fi style."
"""
def generate_add_prompt(new_object, description \\ "", style \\ "") when is_binary(new_object) and is_binary(description) and is_binary(style) do
description_string =
case description do
"" -> ""
_ -> " #{description}"
end
style_string =
case style do
"" -> ""
_ -> ", in a #{style} style"
end
"Add #{new_object}#{description_string} to the image#{style_string}."
end
@doc """
Combines multiple prompt segments into a single prompt.
## Examples
iex> AiReplacePrompt.combine_prompts(["a cat", "sitting on a mat"])
"a cat, sitting on a mat"
iex> AiReplacePrompt.combine_prompts(["a dog", "running in the park", "happy"])
"a dog, running in the park, happy"
"""
def combine_prompts(prompt_segments) when is_list(prompt_segments) do
prompt_segments
|> Enum.join(", ")
end
end