Enhance Your Applications with Image Generation Using Pawanmw/test Cognitive Actions

21 Apr 2025
Enhance Your Applications with Image Generation Using Pawanmw/test Cognitive Actions

The pawanmw/test API offers powerful Cognitive Actions specifically designed for innovative image generation. With the Generate Inpainted Image action, developers can create stunning inpainted images by leveraging user-defined parameters such as image masks, prompts, and various configuration settings. By integrating these pre-built actions into your applications, you can take advantage of advanced image processing capabilities without needing to build complex algorithms from scratch.

Prerequisites

Before you start using the Cognitive Actions, ensure that you have:

  • An API key for the Cognitive Actions platform.
  • Familiarity with JSON for constructing requests and handling responses.

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

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action creates an inpainted image based on a user-defined prompt and various optional parameters to customize the output. This action belongs to the image-generation category and provides flexibility in choosing models, configuring image quality, and more.

Input: The input schema for this action requires a prompt and supports various optional parameters. Below is an overview of the required and optional fields:

  • Required:
    • prompt (string): The main text prompt to guide image generation.
  • Optional:
    • mask (string): URI for the image mask.
    • image (string): URI for an input image.
    • width (integer): Desired width of the output image (256-1440).
    • height (integer): Desired height of the output image (256-1440).
    • goFast (boolean): Toggle for faster predictions.
    • seed (integer): Random seed for reproducibility.
    • modelType (string): Model type for inference (default is "dev").
    • numOutputs (integer): Number of images to generate (1-4).
    • Additional parameters for advanced features such as LoRA weights, aspect ratio, output format, etc.

Example Input:

{
  "goFast": false,
  "prompt": "AI_Pavan discussing finance strategy with a client in their 30s at a home office. Client is looking the laptop AI_Pavan sharing.",
  "loraScale": 1,
  "modelType": "dev",
  "megapixels": "1",
  "numOutputs": 1,
  "extraLoraScale": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "png",
  "numInferenceSteps": 28,
  "imageGuidanceScale": 3,
  "imageOutputQuality": 60,
  "imagePromptStrength": 0.8
}

Output: The action typically returns a URL to the generated image. Below is an example of the output you might receive:

[
  "https://assets.cognitiveactions.com/invocations/9b94d640-859b-459f-9bdd-99d8dca27d7f/e78640c7-b495-4a88-8767-9af58083b6b9.png"
]

Conceptual Usage Example (Python): Here's how you might call this action using 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 = "de602345-928b-4667-8177-4cfe56cc9bb1" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "AI_Pavan discussing finance strategy with a client in their 30s at a home office. Client is looking the laptop AI_Pavan sharing.",
    "loraScale": 1,
    "modelType": "dev",
    "megapixels": "1",
    "numOutputs": 1,
    "extraLoraScale": 1,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "png",
    "numInferenceSteps": 28,
    "imageGuidanceScale": 3,
    "imageOutputQuality": 60,
    "imagePromptStrength": 0.8
}

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, replace the placeholder values with your actual API key and endpoint. The action ID and input payload are structured to match your requirements for generating an inpainted image.

Conclusion

The pawanmw/test Cognitive Actions empower developers to seamlessly integrate advanced image generation capabilities into their applications. By utilizing the Generate Inpainted Image action, you can create customized and high-quality images efficiently. Explore using different parameters to optimize your results, and consider how this powerful functionality can enhance your projects. Happy coding!