Enhance Your App's Creativity: Using AI Mobile Cognitive Actions for Image Generation

22 Apr 2025
Enhance Your App's Creativity: Using AI Mobile Cognitive Actions for Image Generation

In today's digital landscape, the demand for customized visuals is ever-growing. The royaldhkbd/ai-mobile API offers a powerful set of Cognitive Actions designed to help developers easily integrate advanced image generation capabilities into their applications. With features like image inpainting and customizable generation parameters, these actions enable you to produce stunning visuals tailored to your needs.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
  • A basic understanding of JSON and how to structure API requests.

Authentication typically involves passing your API key in the request headers to authorize your access to the service.

Cognitive Actions Overview

Generate Image with Customization

The Generate Image with Customization action allows you to create customized images through image-to-image or inpainting modes. You can specify various parameters such as aspect ratio, image quality, and model type to enhance the image generation process.

Input

The input for this action is structured as follows:

{
  "image": "https://example.com/image.png",
  "prompt": "change the logo text to SAMSUNG in the reference image file",
  "imageFormat": "png",
  "outputCount": 1,
  "guidanceScale": 3.5,
  "mainLoraScale": 1,
  "outputQuality": 90,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageAspectRatio": "4:3",
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

Required Fields:

  • prompt: A text prompt guiding the image generation.

Optional Fields:

  • image: URI of the input image for image-to-image or inpainting modes.
  • imageFormat: Specifies the format of the output images (e.g., webp, jpg, png).
  • outputCount: Number of images to generate (1 to 4).
  • guidanceScale: Adjusts the influence of the text prompt.
  • mainLoraScale: Defines the intensity of the main LoRA application.
  • outputQuality: Sets the quality of saved output images.
  • inferenceModel: Choose between 'dev' or 'schnell' for inference.
  • promptStrength: Determining the extent to which the prompt alters the original image.
  • imageAspectRatio: Defines the aspect ratio of the generated image.
  • numInferenceSteps: Specifies the number of denoising steps.
  • additionalLoraScale: Determines the strength of the additional LoRA application.

Output

The action typically returns a list of generated image URIs. Here's an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/5fee581e-f74c-4959-af23-722255d77207/55cf37da-c3db-4cd1-acc9-31fd607f12f9.png"
]

Conceptual Usage Example (Python)

Here's how you might call this action in Python:

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 = "c33157f0-7fa8-428b-a426-49e22f4b0dfe"  # Action ID for Generate Image with Customization

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/Lstxo06MUsWlWoZCzQnVjflaTKxcRGY7q1XZMcI3k45IL0fQ/replicate-prediction-y9wqkct1vsrm00cjvkpsqsc5hc.png",
    "prompt": "change the logo text to SAMSUNG in the reference image file",
    "imageFormat": "png",
    "outputCount": 1,
    "guidanceScale": 3.5,
    "mainLoraScale": 1,
    "outputQuality": 90,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageAspectRatio": "4:3",
    "numInferenceSteps": 28,
    "additionalLoraScale": 1
}

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, you'll need to replace the placeholder for the API key and the hypothetical endpoint. The payload is structured according to the requirements of the Generate Image with Customization action, allowing you to send a request and retrieve generated images based on your specified parameters.

Conclusion

The royaldhkbd/ai-mobile Cognitive Actions provide a comprehensive solution for developers looking to enhance their applications with advanced image generation capabilities. By leveraging the Generate Image with Customization action, you can create tailored visuals that meet your specific needs. Explore the possibilities and integrate these powerful actions into your projects to captivate your audience with stunning images!