Harnessing Image Generation with Cognitive Actions in sergiosevilla95/ser

22 Apr 2025
Harnessing Image Generation with Cognitive Actions in sergiosevilla95/ser

In the world of artificial intelligence, the ability to generate images based on descriptive prompts opens up exciting possibilities for developers. The sergiosevilla95/ser API offers a powerful Cognitive Action known as Generate Image with Inpainting. This action allows developers to create stunning images through either image-to-image or inpainting modes, enabling rich customization in output quality, dimensions, and more. Leveraging these pre-built actions can save time and effort, allowing developers to focus on building innovative applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making API requests using JSON.
  • Familiarity with Python programming for the conceptual examples provided.

Authentication typically involves passing your API key in the request headers, allowing secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action enables the creation of images with adjustable parameters to suit your specific needs. Whether you're interested in generating a completely new image or modifying an existing one, this action provides a flexible solution.

Input

The input for this action is structured as follows:

  • prompt (required): A descriptive text that guides the image generation process.
  • mask (optional): URI of an image mask for inpainting mode.
  • seed (optional): An integer to specify a random seed for reproducibility.
  • image (optional): URI of an input image for image-to-image transformation.
  • width (optional): Desired width of the generated image (256 to 1440).
  • height (optional): Desired height of the generated image (256 to 1440).
  • modelType (optional): Choose between "dev" or "schnell" for inference.
  • aspectRatio (optional): Defines the aspect ratio of the output image.
  • outputCount (optional): Number of images to generate (1 to 4).
  • outputFormat (optional): Format of the output image (webp, jpg, png).
  • loraIntensity (optional): Intensity of the primary LoRA application.
  • outputQuality (optional): Quality of saved images (0 to 100).
  • promptStrength (optional): Strength of the prompt impact in image generation.
  • additional fields: Various other parameters for fine-tuning the generation process.

Example Input:

{
  "prompt": "\"ser, a creative professional wearing casual yet stylish attire with a modern flair, sitting comfortably in a chair in a creative studio. He is looking directly at the camera, relaxed yet focused, with a calm and professional demeanor. The background features the tools of the office, including design sketches, colorful mood boards, a laptop, and a few art supplies scattered around, but these elements remain softly blurred to emphasize Sergio as the central focus. The lighting is bright yet soft, with natural daylight filtering through large windows, creating a comfortable and energetic atmosphere in the studio. The composition highlights Sergio's calm and focused presence, surrounded by the creative environment that fuels his work.\"",
  "modelType": "dev",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "jpg",
  "loraIntensity": 1,
  "outputQuality": 98,
  "promptStrength": 0.8,
  "accelerateProcess": false,
  "inferenceStepCount": 28,
  "approximateMegapixels": "1",
  "diffusionGuidanceScale": 3,
  "additionalLoraIntensity": 1
}

Output

The action returns a URL pointing to the generated image. Below is an example of the output:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/b0db3f1f-f626-4c58-b5a1-2f1b80c29201/b4096bf4-f6d9-4140-9fe1-7d4e676d2eab.jpg"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Inpainting action using a hypothetical Cognitive Actions endpoint 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 = "b85fad47-ee11-4583-a8a4-f7ed70ec2fe4"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "\"ser, a creative professional wearing casual yet stylish attire with a modern flair, sitting comfortably in a chair in a creative studio. He is looking directly at the camera, relaxed yet focused, with a calm and professional demeanor. The background features the tools of the office, including design sketches, colorful mood boards, a laptop, and a few art supplies scattered around, but these elements remain softly blurred to emphasize Sergio as the central focus. The lighting is bright yet soft, with natural daylight filtering through large windows, creating a comfortable and energetic atmosphere in the studio. The composition highlights Sergio's calm and focused presence, surrounded by the creative environment that fuels his work.\"",
    "modelType": "dev",
    "aspectRatio": "1:1",
    "outputCount": 1,
    "outputFormat": "jpg",
    "loraIntensity": 1,
    "outputQuality": 98,
    "promptStrength": 0.8,
    "accelerateProcess": False,
    "inferenceStepCount": 28,
    "approximateMegapixels": "1",
    "diffusionGuidanceScale": 3,
    "additionalLoraIntensity": 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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Image with Inpainting action. The input payload is constructed according to the specified input schema, ensuring that all required fields are included.

Conclusion

The Generate Image with Inpainting action from the sergiosevilla95/ser API provides developers with a robust tool for generating high-quality images tailored to specific prompts. By utilizing this action, you can enhance your applications with visually appealing content seamlessly. Explore the various customization options to find the perfect settings for your needs, and consider how this technology can power your next project!