Create Stunning Images with MyModelo Cognitive Actions

22 Apr 2025
Create Stunning Images with MyModelo Cognitive Actions

In the realm of AI-driven creativity, the MyModelo Cognitive Actions provide developers with powerful tools for generating stunning images. These actions are designed to leverage advanced inference models, allowing users to create high-quality visuals efficiently. Whether you aim to enhance your applications with image generation capabilities or explore creative possibilities in artistic expression, MyModelo's pre-built actions simplify the process and deliver impressive results.

Prerequisites

Before diving into the implementation of MyModelo Cognitive Actions, ensure you have the following prerequisites:

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
  • Basic Understanding of JSON: Familiarity with JSON is essential as you will be structuring inputs and handling outputs in this format.

Authentication typically involves passing your API key in the request headers when invoking the actions.

Cognitive Actions Overview

Generate Image with MyModelo

The Generate Image with MyModelo action allows you to create images using either the 'dev' or 'schnell' inference models, catering to your specific needs for speed or quality. This action supports image-to-image transformations, inpainting, and various customization options to tailor the generated images to your specifications.

Input

The input schema for this action requires the following fields:

  • prompt (required): A text description guiding the image generation.
  • mask (optional): URI of the image mask for inpainting.
  • seed (optional): An integer for reproducible image generation.
  • image (optional): URI of an input image for transformations.
  • width (optional): Width of the generated image (256 to 1440).
  • height (optional): Height of the generated image (256 to 1440).
  • goFast (optional): Boolean to optimize for speed (default: false).
  • modelType (optional): Select from 'dev' (default) or 'schnell'.
  • numOutputs (optional): Number of image outputs to generate (1-4).
  • imageFormat (optional): Specify 'webp', 'jpg', or 'png' for the output format.
  • guidanceScale (optional): Controls the guidance during the diffusion process (default: 3).
  • outputQuality (optional): Quality percentage for output files (0-100).
  • aspectRatioSetting (optional): Choose from various aspect ratios (default: '1:1').
  • additional fields related to LoRA weights and settings.

Example Input:

{
  "goFast": false,
  "prompt": "\"Primer plano de MyModelo,  con gafas de sol verdes, sonriendo con confianza...\"",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "imageFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "numInferenceSteps": 28,
  "aspectRatioSetting": "16:9"
}

Output

The action typically returns a list of URLs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/61d49fb9-c37e-417f-b948-23eea05443bc/69870902-ce78-4182-a328-8d3c4eb2e089.webp"
]

Conceptual Usage Example (Python)

Here’s how you might invoke the Generate Image with MyModelo 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 = "dc05d16c-3bce-47e9-96cc-bb1cf0939d7e" # Action ID for Generate Image with MyModelo

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "\"Primer plano de MyModelo,  con gafas de sol verdes, sonriendo con confianza...\"",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "imageFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "numInferenceSteps": 28,
    "aspectRatioSetting": "16:9"
}

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}
    )
    response.raise_for_status()  # Raise an exception for bad status codes

    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 MyModelo action. The payload object is structured according to the required input schema, ensuring that all necessary parameters are included.

Conclusion

The MyModelo Cognitive Actions provide developers with an efficient avenue to integrate advanced image generation capabilities into their applications. By leveraging these actions, you can create unique visuals tailored to your specifications, enhancing user engagement and experience. Explore various use cases, from content creation to artistic projects, and unlock the full potential of AI-generated imagery in your applications!