Harnessing the Power of Image Generation with vladasanadev/vlada Cognitive Actions

21 Apr 2025
Harnessing the Power of Image Generation with vladasanadev/vlada Cognitive Actions

In the evolving landscape of artificial intelligence, the ability to generate and manipulate images has become increasingly important. The vladasanadev/vlada API offers an innovative set of Cognitive Actions that enable developers to create stunning images using customizable inpainting techniques. These pre-built actions simplify the integration of advanced image generation capabilities into your applications, making it easier for developers to focus on delivering value to their users.

Prerequisites

Before you dive into using the Cognitive Actions, there are a few general requirements you need to fulfill:

  • API Key: Ensure you have a valid API key for the Cognitive Actions platform. This key will be essential for authenticating your requests.
  • Endpoint Setup: You will need the correct endpoint URL to execute the actions, which will be provided within the context of your development environment.

Authentication typically involves passing your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images by utilizing a customizable inpainting process. This action supports various options including aspect ratio, resolution, and output format, alongside model selection for optimized inference steps.

Input

The input schema for this action requires the following fields:

  • prompt (required): A descriptive text prompt for generating the image.
  • image (optional): URI of an input image used for inpainting.
  • mask (optional): URI of an image mask for inpainting.
  • width (optional): Specifies the width of the generated image.
  • height (optional): Specifies the height of the generated image.
  • model (optional): Select the model for inference.
  • goFast (optional): Enable fast predictions.
  • numOutputs (optional): Number of output images to generate.
  • aspectRatio (optional): Specify the aspect ratio for image generation.
  • outputFormat (optional): Choose the format for the output images.
  • guidanceScale (optional): Adjust the guidance scale for the diffusion process.
  • outputQuality (optional): Set the quality for the saved images.
  • loraScale (optional): Controls the intensity of the primary LoRA.
  • numInferenceSteps (optional): The number of denoising steps.

Here’s an example of a valid input JSON payload:

{
  "image": "https://replicate.delivery/pbxt/MPUDqQ5M7SrnhmUsG34fOXqqhXFdGobpTMSo0hkjswY1GaEM/replicate-prediction-swgbacbp9nrmc0cmppr83wnhbw.webp",
  "model": "dev",
  "goFast": false,
  "prompt": "make vlada face subtle beautiful portrait with her beautiful golden eyes and 3D futuristic mask golden color",
  "loraScale": 1,
  "megapixels": "1",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output

The output from this action typically returns an array of image URLs, indicating the generated images. Here’s an example of a valid output:

[
  "https://assets.cognitiveactions.com/invocations/cac74e20-18a8-475d-ae19-6b83fcb7a039/c39fb603-ee01-4ed9-9a39-ffed5a8dd18f.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Inpainting 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 = "774c11bc-7cb6-43e6-8edb-aadbeb42a256" # Action ID for Generate Image with Inpainting

# Construct the input payload
payload = {
    "image": "https://replicate.delivery/pbxt/MPUDqQ5M7SrnhmUsG34fOXqqhXFdGobpTMSo0hkjswY1GaEM/replicate-prediction-swgbacbp9nrmc0cmppr83wnhbw.webp",
    "model": "dev",
    "goFast": False,
    "prompt": "make vlada face subtle beautiful portrait with her beautiful golden eyes and 3D futuristic mask golden color",
    "loraScale": 1,
    "megapixels": "1",
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "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()

    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, you'll need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the action's input schema. The endpoint URL and request structure are illustrative, aiming to guide you in making the correct API calls.

Conclusion

The vladasanadev/vlada set of Cognitive Actions, particularly the Generate Image with Inpainting action, opens up exciting possibilities for developers looking to integrate image generation into their applications. By utilizing these actions, you can enhance your application's capabilities and offer users innovative features. Consider exploring additional use cases, such as creative content generation or enhancing existing images with inpainting techniques. Happy coding!