Enhance Your App with Image Generation using swetabhsaurav/saladbowl Cognitive Actions

24 Apr 2025
Enhance Your App with Image Generation using swetabhsaurav/saladbowl Cognitive Actions

In today's digital landscape, image generation has become an essential tool for developers looking to enhance user experience and creativity within their applications. The swetabhsaurav/saladbowl Cognitive Actions offer powerful capabilities for generating customized images through advanced inpainting techniques. With adjustable parameters for image size, quality, and model selection, these actions can seamlessly integrate into your app, allowing for dynamic content creation.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests and handling JSON data.
  • Basic knowledge of Python programming to utilize the conceptual code examples provided.

For authentication, you will typically pass your API key in the request headers, allowing you to securely execute the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

Description: Generate customized images using advanced inpainting techniques, with adjustable parameters for image size, quality, and model selection. The operation supports image-to-image transformations, fast mode for speed optimization, and a variety of aspect ratios and output formats.

Category: Image Processing

Input

The Generate Image with Inpainting action requires the following input:

  • Required:
    • prompt (string): A textual description of the desired image.
  • Optional:
    • mask (string): URI of the image mask used for inpainting mode.
    • seed (integer): Random seed for reproducible generation.
    • image (string): URI of input image for image-to-image or inpainting mode.
    • model (string): Model used for inference (dev or schnell).
    • width (integer): Width of the generated image (applicable when aspect_ratio is 'custom').
    • height (integer): Height of the generated image (applicable when aspect_ratio is 'custom').
    • goFast (boolean): Optimize for speed using an fp8 quantized model.
    • extraLora (string): Load additional LoRA weights.
    • loraScale (number): Strength of the main LoRA application.
    • megapixels (string): Approximate number of megapixels for generated image.
    • numOutputs (integer): Number of outputs to generate.
    • guidanceScale (number): Guidance scale for the diffusion process.
    • outputQuality (integer): Quality when saving the output images (0 to 100).
    • extraLoraScale (number): Strength of the extra LoRA application.
    • promptStrength (number): Prompt strength when using img2img.
    • variableWeights (string): Input variable LoRA weights.
    • aspectRatioString (string): Aspect ratio for the generated image.
    • numInferenceSteps (integer): Number of denoising steps.
    • outputImageFormat (string): Format of the output images.
    • disableSafetyChecker (boolean): Option to disable the safety checker during image generation.

Example Input:

{
  "model": "dev",
  "prompt": "SLDBWL is a salad bowl. an image of wooden SLDBWL in its true color and size and texture with some salad in it",
  "loraScale": 0.77,
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "aspectRatioString": "1:1",
  "numInferenceSteps": 28,
  "outputImageFormat": "webp"
}

Output

The Generate Image with Inpainting action typically returns an array of URLs pointing to the generated images. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/a1455eac-20bb-476f-82e4-adde6b81ff30/e6a5aaa6-9c10-4267-88b4-13d8772f409f.webp"
]

Conceptual Usage Example (Python)

Here’s how you can 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 = "491048cc-eccd-4e53-bbf9-9a72e23e35e5"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "SLDBWL is a salad bowl. an image of wooden SLDBWL in its true color and size and texture with some salad in it",
    "loraScale": 0.77,
    "numOutputs": 1,
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "aspectRatioString": "1:1",
    "numInferenceSteps": 28,
    "outputImageFormat": "webp"
}

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 the above code snippet, you'll notice that the action ID and input payload are structured as required. The endpoint URL and request structure are illustrative and might differ in practice.

Conclusion

The swetabhsaurav/saladbowl Cognitive Actions offer developers an efficient way to integrate advanced image generation capabilities into their applications. By utilizing the Generate Image with Inpainting action, you can create customized visuals that enhance user engagement and creativity. Explore further use cases, experiment with different parameters, and start transforming your applications today!