Create Custom Emoji Images with the fofr/sdxl-emoji Cognitive Actions

23 Apr 2025
Create Custom Emoji Images with the fofr/sdxl-emoji Cognitive Actions

In today's digital landscape, integrating rich visual content into applications is essential for engaging users. The fofr/sdxl-emoji Cognitive Actions bring the power of image generation directly to your fingertips, enabling you to create images in the distinctive style of Apple Emojis. By leveraging a fine-tuned SDXL model, these actions allow for extensive customization through prompts and various image generation parameters, including img2img and inpainting modes.

This blog post will guide you through the capabilities of the Generate Emoji Style Images action, detailing its inputs and outputs, and providing a conceptual code example for implementation.

Prerequisites

Before getting started, ensure you have:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON format and Python programming to structure your requests.

Authentication typically involves passing your API key in the headers of your HTTP request.

Cognitive Actions Overview

Generate Emoji Style Images

Purpose: This action generates images in the style of Apple Emojis, allowing users to create customized visual content guided by specific prompts and parameters.

Category: Image Generation

Input

The input for this action is structured in JSON format and includes various parameters to customize the image generation process. Here’s a breakdown of the required fields based on the input_schema:

  • prompt (string): Text prompt guiding the image generation. Example: "A TOK emoji of a man" (default: "An astronaut riding a rainbow unicorn").
  • width (integer): Width of the output image in pixels. Example: 1024 (default: 1024).
  • height (integer): Height of the output image in pixels. Example: 1024 (default: 1024).
  • refine (string): Style refinement choice. Example: "no_refiner" (default: "no_refiner").
  • loraScale (number): LoRA additive scale factor between 0 and 1. Example: 0.6.
  • scheduler (string): Scheduler algorithm for image generation. Example: "K_EULER" (default: "K_EULER").
  • guidanceScale (number): Scaling factor for classifier-free guidance. Example: 7.5 (default: 7.5).
  • applyWatermark (boolean): Option to apply a watermark. Example: false (default: true).
  • negativePrompt (string): Negative prompt for undesired features. Example: "" (default: "").
  • promptStrength (number): Factor for prompt strength when using img2img or inpaint. Example: 0.8 (default: 0.8).
  • numberOfOutputs (integer): Number of images to output (1 to 4). Example: 1 (default: 1).
  • highNoiseFraction (number): Fraction of noise for refinement. Example: 0.8 (default: 0.8).
  • numberOfInferenceSteps (integer): Number of denoising steps (1 to 500). Example: 50 (default: 50).

Here is a sample input JSON payload:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A TOK emoji of a man",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

Output

The output of this action is typically a URL linking to the generated image. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/d29e8294-35d0-4510-8e66-23de0c2e0cfd/a9bfd6b2-9993-4d39-8b73-1209e5b527d0.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet illustrating how to call the Generate Emoji Style Images action using a hypothetical Cognitive Actions execution endpoint:

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 = "69548f06-9ce3-4bbd-9f2a-5acf726b1134"  # Action ID for Generate Emoji Style Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A TOK emoji of a man",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "guidanceScale": 7.5,
    "applyWatermark": False,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "numberOfInferenceSteps": 50
}

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 code snippet, ensure to replace the API key and endpoint with your actual credentials. The action ID and input payload are structured according to the specifications we discussed.

Conclusion

The fofr/sdxl-emoji Cognitive Actions provide a powerful way for developers to create customized emoji-style images with ease. By leveraging the capabilities of the Generate Emoji Style Images action, you can enrich your applications with unique visual content that resonates with your users.

Now that you understand how to use this action, consider exploring various prompts and parameters to see the diverse range of images you can create. Happy coding!