Create Stunning Images with the cesarvega/my-model-astrea-v2 Cognitive Actions

21 Apr 2025
Create Stunning Images with the cesarvega/my-model-astrea-v2 Cognitive Actions

In today's digital landscape, the ability to generate images from text prompts opens up a world of possibilities for developers. The cesarvega/my-model-astrea-v2 API provides a powerful Cognitive Action that utilizes advanced image-to-image translation and inpainting techniques. This action allows developers to create high-quality images based on descriptive prompts, making it an invaluable tool for applications in creative design, marketing, and more.

Prerequisites

Before diving into the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON and HTTP requests.

Authentication typically involves including your API key in the request headers, allowing secure access to the API's functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

Description: This action generates images based on a given text prompt by utilizing image-to-image translation and inpainting techniques. It optimizes for speed and quality through various model options.

Input

The input for this action requires the following fields based on its schema:

{
  "prompt": "a photo of ASTREA washing in shorts a Purple Lamborghini diablo, no glasses, in Miami",
  "model": "dev",
  "goFast": false,
  "loraScale": 1,
  "guidanceScale": 8,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.9,
  "numberOfOutputs": 1,
  "aspectRatioOption": "1:1",
  "imageOutputFormat": "webp",
  "approximateMegapixels": "1",
  "numberOfInferenceSteps": 35
}
  • Required Field:
    • prompt: The text guiding the image generation (mandatory).
  • Optional Fields:
    • mask: URI of an image mask for inpainting.
    • seed: Random seed value for reproducibility.
    • image: URI of an input image for image-to-image or inpainting mode.
    • width: Width of the generated image.
    • height: Height of the generated image.
    • numberOfOutputs: Number of images to generate (1-4).
    • aspectRatioOption: Specifies the aspect ratio of the generated image.
    • imageOutputFormat: Format for the output image (webp, jpg, png).

Output

The action typically returns a URL to the generated image:

[
  "https://assets.cognitiveactions.com/invocations/d6820e4c-8557-402d-a4ba-a7aa00326985/41269c99-851e-4030-9136-d4808292df2a.webp"
]

This URL points to the generated image, which can be retrieved and used directly in your applications.

Conceptual Usage Example (Python)

Here’s how you could structure a Python script to call the action:

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 = "9d2402e1-1dec-413c-ae28-84df4456f04a" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "a photo of ASTREA washing in shorts a Purple Lamborghini diablo, no glasses, in Miami",
    "loraScale": 1,
    "guidanceScale": 8,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.9,
    "numberOfOutputs": 1,
    "aspectRatioOption": "1:1",
    "imageOutputFormat": "webp",
    "approximateMegapixels": "1",
    "numberOfInferenceSteps": 35
}

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 variable is structured according to the action's input schema, ensuring all required fields are included.

Conclusion

The cesarvega/my-model-astrea-v2 Cognitive Actions provide developers with a robust solution for generating images from text prompts. By leveraging advanced inpainting techniques and customizable parameters, you can create high-quality visual content that meets your project's unique needs.

Consider exploring additional use cases or combining this action with other services to unlock even more creative potential in your applications. Happy coding!