Unleash Your Creativity: Integrating Image Generation with Cognitive Actions in Somras1

23 Apr 2025
Unleash Your Creativity: Integrating Image Generation with Cognitive Actions in Somras1

In today's digital landscape, the demand for high-quality image generation is soaring, whether it's for marketing campaigns, content creation, or artistic endeavors. The royronit/somras1 API introduces a powerful set of Cognitive Actions that enable developers to create stunning images with precise control over various parameters. This blog post will walk you through the Generate Image with Inpainting action, highlighting its capabilities and how to integrate it into your applications effectively.

Prerequisites

Before you begin using the Cognitive Actions, ensure that you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with JSON and HTTP requests.

For authentication, you will typically pass your API key in the request headers, allowing you to securely access the API's functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using advanced techniques, providing detailed control over the generation process, including aspect ratio and output quality. You can leverage different models for speed and quality, enabling fast generation and the use of custom LoRA weights. This action is particularly useful for generating images that require specific adjustments or enhancements.

Input

The input for this action is structured as follows:

  • prompt (string, required): A descriptive text that guides the image generation process.
  • mask (string, optional): URI of the image mask for inpainting, overriding size specifications.
  • seed (integer, optional): A seed value for reproducibility.
  • image (string, optional): URI of an input image for inpainting.
  • model (string, optional): Choose between "dev" for detailed generation or "schnell" for faster processing.
  • width (integer, optional): The width of the generated image (must be a multiple of 16).
  • height (integer, optional): The height of the generated image (must be a multiple of 16).
  • fastMode (boolean, optional): Enable speed-optimized execution.
  • megapixels (string, optional): Approximate number of megapixels for output.
  • aspectRatio (string, optional): Aspect ratio settings for the output image.
  • guidanceLevel (number, optional): Scale for guidance during generation (0-10).
  • numberOfOutputs (integer, optional): How many images to generate per request (1-4).
  • imageOutputFormat (string, optional): Format for the output images (webp, jpg, png).
  • imageOutputQuality (integer, optional): Quality level for output images (0-100).

Example Input:

{
  "seed": 2341,
  "model": "dev",
  "prompt": "A stunningly elegant model gazes confidently at the camera, clutching a mysterious bottle of rasa1310 style drink. The scene unfolds on a high fashion haute couture runway, with the model exuding glamour and poise. The image is a photograph capturing a moment of high fashion allure.",
  "aspectRatio": "16:9",
  "guidanceLevel": 3.5,
  "mainLoraScale": 1,
  "promptStrength": 0.8,
  "numberOfOutputs": 2,
  "imageOutputFormat": "webp",
  "imageOutputQuality": 90,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 30
}

Output

The output of this action typically consists of URLs to the generated images. The number of images returned corresponds to the numberOfOutputs parameter specified in the input.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/c632459d-9518-470b-8448-6531dafc562f/a4908fc0-7b1d-41e1-9e53-5129afb09bf1.webp",
  "https://assets.cognitiveactions.com/invocations/c632459d-9518-470b-8448-6531dafc562f/6211fe66-24d6-4de2-99d8-644fd35ed31e.webp"
]

Conceptual Usage Example (Python)

Here's how you can use the Generate Image with Inpainting action in your application:

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 = "8ddda1b4-7b34-4bb5-bb1d-c423fd43a6ea"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "seed": 2341,
    "model": "dev",
    "prompt": "A stunningly elegant model gazes confidently at the camera, clutching a mysterious bottle of rasa1310 style drink. The scene unfolds on a high fashion haute couture runway, with the model exuding glamour and poise.",
    "aspectRatio": "16:9",
    "guidanceLevel": 3.5,
    "mainLoraScale": 1,
    "promptStrength": 0.8,
    "numberOfOutputs": 2,
    "imageOutputFormat": "webp",
    "imageOutputQuality": 90,
    "additionalLoraScale": 1,
    "numberOfInferenceSteps": 30
}

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 payload is structured according to the action's requirements, demonstrating how to set various parameters for image generation.

Conclusion

The Generate Image with Inpainting action from the royronit/somras1 API empowers developers to create visually stunning images with remarkable control over the generation process. Whether you're looking to generate content for marketing, artistic projects, or other applications, these Cognitive Actions can significantly enhance your creative capabilities. Explore further use cases or experiment with different parameters to fully leverage the potential of this powerful tool.