Generate Stunning Images with Inpainting Using Talyfire Cognitive Actions

22 Apr 2025
Generate Stunning Images with Inpainting Using Talyfire Cognitive Actions

In the exciting world of image generation, the talyfire/taly API offers a powerful set of capabilities through its Cognitive Actions. One of the standout features is the ability to generate images based on text prompts, including advanced options like image inpainting and customization of various image properties. This guide will walk you through how to leverage these pre-built actions to enhance your applications with creative image generation.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic familiarity with making HTTP requests and handling JSON data in your preferred programming language.

For authentication, you will typically send your API key in the request headers, allowing you to securely access the image generation features.

Cognitive Actions Overview

Generate Image with Inpainting

Purpose:
This action generates images based on a text prompt and supports image inpainting, allowing users to customize image properties such as size, quality, and format.

Category: Image Generation

Input

The Generate Image with Inpainting action requires a well-structured input. Here’s a breakdown of the required and optional fields based on the input schema:

  • Required:
    • prompt (string): Text input prompt for generating the image. Example: "a picture of talybiz77, which is a woman, red-brown hair, green-brown eyes, fair skin standing in empty room"
  • Optional:
    • image (string): URI for an input image used in image-to-image or inpainting mode.
    • mask (string): URI for an image mask used in image inpainting mode.
    • width (integer): Specifies the width of the generated image (256-1440).
    • height (integer): Specifies the height of the generated image (256-1440).
    • goFast (boolean): Enables faster predictions.
    • numOutputs (integer): Number of generated images (1-4).
    • guidanceScale (number): Controls the guidance scale for the diffusion process (0-10).
    • outputQuality (integer): Quality of saved output images (0-100).

Example Input:

{
  "image": "https://replicate.delivery/pbxt/MhpWsoE8HlEACmLNuPWBlUQBTLqlZADVleVYxH6TEYqBryZQ/WhatsApp%20Image%202025-03-22%20at%2023.11.21.jpeg",
  "goFast": false,
  "prompt": "a picture of talybiz77, which is a woman, red-brown hair, green-brown eyes, fair skin standing in empty room",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 28
}

Output

The action typically returns a URL pointing to the generated image. For instance:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/54dc7ac2-fb92-4be2-bec8-8311094e728e/855055ce-4cca-4032-802c-d8ac5d5be359.webp"
]

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 = "c47c4631-c05d-4243-bb02-432f222b232e" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MhpWsoE8HlEACmLNuPWBlUQBTLqlZADVleVYxH6TEYqBryZQ/WhatsApp%20Image%202025-03-22%20at%2023.11.21.jpeg",
    "goFast": False,
    "prompt": "a picture of talybiz77, which is a woman, red-brown hair, green-brown eyes, fair skin standing in empty room",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "numInferenceSteps": 28
}

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, we set the action_id to the ID of the Generate Image with Inpainting action and structure the input JSON payload according to the requirements. The response from the API will contain the URL of the generated image.

Conclusion

The talyfire/taly Cognitive Actions open up exciting opportunities for developers looking to integrate advanced image generation capabilities into their applications. By utilizing the Generate Image with Inpainting action, you can transform simple text prompts into stunning visual content, enhancing user engagement and creativity.

Explore further by experimenting with different input options and combining various actions to create unique experiences tailored to your application's needs!