Add Googly Eyes to Images with the fofr/sdxl-googly-eyes Cognitive Actions

Integrating playful elements into images can enhance user engagement and creativity. The fofr/sdxl-googly-eyes API provides a powerful Cognitive Action that allows developers to apply a unique googly eye effect to images. By leveraging a fine-tuned SDXL model, this action empowers you to add whimsical touches to any subject, refine styles, and even adjust image dimensions. In this post, we'll explore how to use this Cognitive Action effectively in your applications.
Prerequisites
Before you start using the Cognitive Actions, you will need to have an API key for the Cognitive Actions platform. This key will be used for authentication, typically by passing it in the headers of your API requests. Ensure you have access to the API endpoint for executing the actions.
Cognitive Actions Overview
Apply Googly Eye Effect
The Apply Googly Eye Effect action enhances images by adding googly eyes to subjects. This action allows for various customization options, including style refinement, image dimensions, and watermarking.
Input
The input schema for this action is defined by a structured object with several properties. Here’s a breakdown of the required and optional fields:
- mask (string, optional): Input mask for inpaint mode (URI).
- seed (integer, optional): Random seed for image generation.
- image (string, required): URI of the input image.
- width (integer, optional): Width of the output image in pixels (default: 1024).
- height (integer, optional): Height of the output image in pixels (default: 1024).
- prompt (string, optional): Text prompt for guiding image generation (default: "An astronaut riding a rainbow unicorn").
- refineStyle (string, optional): Style for refining the image (options: no_refiner, expert_ensemble_refiner, base_image_refiner).
- scheduleType (string, optional): Scheduling algorithm for image generation (default: K_EULER).
- additiveScale (number, optional): Scale value for LoRA (range: 0 to 1, default: 0.6).
- enableWatermark (boolean, optional): Whether to apply a watermark (default: true).
- numberOfOutputs (integer, optional): Number of images to generate (default: 1, maximum: 4).
- strengthOfPrompt (number, optional): Impact strength of the prompt (range: 0 to 1, default: 0.8).
- highNoiseFraction (number, optional): Fraction of noise utilized by the expert ensemble refiner (range: 0 to 1, default: 0.8).
- negativeInputPrompt (string, optional): Negates elements from the image.
- numberOfDenoisingSteps (integer, optional): Total steps used during the denoising process (range: 1 to 500, default: 50).
- classifierGuidanceScale (number, optional): Scale parameter for classifier-free guidance (range: 1 to 50, default: 7.5).
Example Input:
{
"width": 768,
"height": 768,
"prompt": "A photo of TOK eyes on a soup",
"refineStyle": "no_refiner",
"scheduleType": "K_EULER",
"additiveScale": 0.7,
"enableWatermark": false,
"numberOfOutputs": 1,
"strengthOfPrompt": 0.8,
"highNoiseFraction": 0.8,
"negativeInputPrompt": "old, rusty, decayed",
"numberOfDenoisingSteps": 25,
"classifierGuidanceScale": 7.5
}
Output
The action typically returns an array of image URLs that contain the modified images with googly eyes applied.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/68d476f6-b5d5-436e-82b2-a7e3279f1bad/32d42bd8-2984-4eae-89f4-0fbc4d87f80f.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how you might call this Cognitive Action using Python. This snippet demonstrates how to structure the input payload and make an API request:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "767aebf5-12d2-468b-9003-a3f8b0327fea" # Action ID for Apply Googly Eye Effect
# Construct the input payload based on the action's requirements
payload = {
"width": 768,
"height": 768,
"prompt": "A photo of TOK eyes on a soup",
"refineStyle": "no_refiner",
"scheduleType": "K_EULER",
"additiveScale": 0.7,
"enableWatermark": False,
"numberOfOutputs": 1,
"strengthOfPrompt": 0.8,
"highNoiseFraction": 0.8,
"negativeInputPrompt": "old, rusty, decayed",
"numberOfDenoisingSteps": 25,
"classifierGuidanceScale": 7.5
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body: {e.response.text}")
In this example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload matches the required schema for the action, ensuring that all necessary parameters are provided.
Conclusion
The Apply Googly Eye Effect action from the fofr/sdxl-googly-eyes API is a fun and creative way to enhance images programmatically. By utilizing the customization options available, developers can create unique content that engages users and adds a playful touch to their applications. Whether you are adding googly eyes to a photo for a marketing campaign or simply for entertainment, this action opens up many possibilities for image manipulation. Start integrating it into your applications today and let your creativity shine!