Enhance Your Applications with Image Generation Using franfernandez93/generador_patri Actions

22 Apr 2025
Enhance Your Applications with Image Generation Using franfernandez93/generador_patri Actions

In the world of AI and machine learning, image generation has become a powerful tool for developers looking to enhance their applications. The franfernandez93/generador_patri API provides a robust set of Cognitive Actions designed for image generation through advanced techniques such as inpainting. These pre-built actions enable developers to create custom images based on detailed prompts and various parameters, streamlining the integration process into their applications.

Prerequisites

Before diving into the integration, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic understanding of JSON and RESTful API calls to format your inputs correctly.

Authentication typically involves passing the API key in the request headers, allowing you to access the capabilities of the Cognitive Actions service.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows developers to perform image generation using inpainting techniques. This action supports various customizable parameters, including the mask image, output format, and guidance scale.

Category: Image Generation

Input

The input for this action requires a JSON object containing the following fields:

  • prompt (required): A detailed description of the image to be generated.
  • mask (optional): A URI for an image mask used in image inpainting mode.
  • image (optional): A URI for an input image used in image-to-image or inpainting mode.
  • model (optional): Specifies the model to use for inference (dev for detailed outputs or schnell for faster predictions).
  • width (optional): The width of the generated image (only if aspect ratio is set to custom).
  • height (optional): The height of the generated image (only if aspect ratio is set to custom).
  • aspectRatio (optional): Specifies the aspect ratio for the generated image.
  • outputCount (optional): The number of images to generate (1 to 4).
  • outputFormat (optional): Defines the file format for the output images.
  • guidanceScale (optional): Controls the guidance scale for the diffusion process.
  • promptStrength (optional): Controls how strongly the prompt affects the image generation.
  • loraIntensity (optional): Adjusts the strength of the LoRA application.

Example Input:

{
  "model": "dev",
  "width": 746,
  "goFast": false,
  "height": 606,
  "prompt": "The image shows a beautiful woman named PatriMarin sitting in a modern and elegant beauty center...",
  "aspectRatio": "1:1",
  "outputCount": 4,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numInferenceSteps": 28
}

Output

The action typically returns an array of URLs pointing to the generated images. Each URL represents a different image generated based on the input prompt.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/7ae0e609-968d-4fe5-bbb3-8d91817cdeaa/d36c8cd3-28d7-402b-b496-c454daeddcfd.webp",
  "https://assets.cognitiveactions.com/invocations/7ae0e609-968d-4fe5-bbb3-8d91817cdeaa/e43adcd5-9fc0-40ac-82a5-752ebaac2ea2.webp",
  "https://assets.cognitiveactions.com/invocations/7ae0e609-968d-4fe5-bbb3-8d91817cdeaa/f87680d9-0e45-4bc7-a4c3-1a926f44ae5a.webp",
  "https://assets.cognitiveactions.com/invocations/7ae0e609-968d-4fe5-bbb3-8d91817cdeaa/27c0be66-a8e8-410b-9dc6-a8757488f6bf.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call this action using Python. This conceptual example demonstrates structuring the input JSON payload correctly.

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 = "87ad2d01-85ed-4670-a9a9-7e762af45bdf" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 746,
    "goFast": False,
    "height": 606,
    "prompt": "The image shows a beautiful woman named PatriMarin sitting in a modern and elegant beauty center...",
    "aspectRatio": "1:1",
    "outputCount": 4,
    "outputFormat": "webp",
    "guidanceScale": 3,
    "loraIntensity": 1,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "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:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The payload object is structured according to the required input for the action.
  • The action ID is specified for the Generate Image with Inpainting action.
  • The response is printed in a formatted manner, allowing you to easily view the output URLs.

Conclusion

The franfernandez93/generador_patri Cognitive Actions offer a powerful method for developers to integrate advanced image generation capabilities into their applications. By leveraging the Generate Image with Inpainting action, you can create stunning, customized images based on rich prompts and parameters. Next steps could include experimenting with different prompts, exploring variations in output formats, and integrating this functionality into user-facing applications for an enhanced user experience. Happy coding!