Generate Stunning Images with baaivision/emu3-gen Cognitive Actions

24 Apr 2025
Generate Stunning Images with baaivision/emu3-gen Cognitive Actions

In the fast-evolving realm of artificial intelligence, the baaivision/emu3-gen API brings an innovative approach to image generation. By harnessing the power of the Emu3 model, developers can create high-quality images based on simple text prompts. This set of Cognitive Actions empowers you to generate visuals in flexible resolutions and styles, all without the complexities of diffusion or compositional architectures. In this article, we will explore how to integrate the "Generate Images with Emu3" action into your applications.

Prerequisites

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

  • An API key for the baaivision/emu3-gen service.
  • Basic knowledge of making HTTP requests in Python.

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the image generation capabilities.

Cognitive Actions Overview

Generate Images with Emu3

The Generate Images with Emu3 action allows you to utilize the Emu3 model for producing high-quality images based on next-token prediction. This action falls under the image-generation category and provides a straightforward method to create unique visuals from textual descriptions.

Input

The input for this action is structured as follows:

{
  "prompt": "a portrait of an astronaut riding a unicorn.",
  "guidanceScale": 3,
  "negativePrompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry.",
  "positivePrompt": "masterpiece, film grained, best quality."
}
  • prompt (string): This is the essential input that guides the model's image generation. It should contain a concise description of the desired content.
  • guidanceScale (number): A value between 1 and 20 that determines the strength of the guidance used during generation. Recommended values typically lie between 3 to 7.
  • negativePrompt (string): A list of undesirable elements to avoid in the generated image, helping refine the output.
  • positivePrompt (string): A list of desirable qualities to emphasize in the output image.

Output

When you invoke the Generate Images with Emu3 action, you can expect an output similar to the following:

https://assets.cognitiveactions.com/invocations/13991551-7f7d-4679-bf61-58dacd306487/8326ba6f-c2d0-4274-ba31-b6ff9a736e6b.png

This URL points to the generated image, which can be displayed or utilized as needed in your application.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Images with Emu3 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 = "4f0edc88-e4f5-469b-8e98-b6fe63087a73"  # Action ID for Generate Images with Emu3

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "a portrait of an astronaut riding a unicorn.",
    "guidanceScale": 3,
    "negativePrompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry.",
    "positivePrompt": "masterpiece, film grained, best quality."
}

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 built according to the action's input schema.
  • The API request is structured to send the action ID and inputs in the JSON payload.

Conclusion

The baaivision/emu3-gen Cognitive Actions offer a powerful and straightforward way for developers to generate stunning images based on textual prompts. By leveraging the capabilities of the Emu3 model, you can create visuals that align perfectly with your creative vision. Next steps could involve experimenting with different prompts and parameters to discover the full potential of this action in your applications. Happy coding!