Create Stunning Custom Images Effortlessly with Grievous

25 Apr 2025
Create Stunning Custom Images Effortlessly with Grievous

In today's digital landscape, the demand for high-quality visuals is ever-increasing. Grievous offers a powerful set of Cognitive Actions that streamline the image generation process, allowing developers to create stunning images using advanced techniques. With the ability to generate custom images through inpainting and image-to-image transformations, developers can focus on creativity while Grievous handles the technical complexities. This service is designed for speed and flexibility, making it an ideal solution for various applications, from marketing and content creation to game development and art projects.

Common use cases for Grievous include generating unique artwork based on specific prompts, creating promotional materials with tailored visuals, or enhancing existing images with new elements. By leveraging the advanced capabilities of Grievous, developers can elevate their projects and deliver visually striking content that captures attention.

Before diving in, you'll need a Grievous Cognitive Actions API key and a basic understanding of how to make API calls to utilize these features effectively.

Generate Custom Image

The Generate Custom Image action allows you to create images from detailed prompts, utilizing advanced inpainting and image-to-image techniques. This action solves the challenge of producing unique and high-quality visuals by providing detailed control over various image properties such as aspect ratio, quality, and model selection.

Input Requirements

The input for this action requires a structured object that includes the following essential properties:

  • prompt: A descriptive text that guides the image generation process.
  • mask: An optional image mask for inpainting mode.
  • image: An optional input image for image-to-image transformations.
  • width and height: Dimensions for the generated image, applicable when using a custom aspect ratio.
  • megapixels: Specifies the approximate number of megapixels for the output image.
  • Additional parameters include settings for output quality, inference model selection, and LoRA intensity.

Expected Output

The expected output is a URL pointing to the generated image, which can be accessed and used in various applications.

Use Cases for this specific action

  • Art and Design: Artists can create unique pieces based on specific themes or ideas, helping to inspire new concepts and designs.
  • Marketing: Marketers can generate tailored images for campaigns, ensuring that visuals align closely with messaging and branding.
  • Gaming: Game developers can produce concept art or in-game assets that fit their narrative and aesthetic needs.
  • Content Creation: Bloggers and content creators can quickly generate visuals that enhance their articles and attract readers.

```python
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "9f8c877a-6e67-4305-9465-34e701a85bcf" # Action ID for: Generate Custom Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "\"A close-up headshot of General Grievous in the dimly lit hallway of a Venator-class Star Destroyer, his sinister mechanical face illuminated by the flickering emergency lights. His piercing yellow eyes glow menacingly, exuding a sense of danger and cunning. The red hue of the ship’s alert systems casts an ominous light across his metallic features, highlighting the intricate details of his cybernetic design. Sparks fly from damaged panels behind him, while a light haze of smoke swirls around, adding depth and tension to the scene. The atmosphere is cinematic and photorealistic, capturing the essence of Star Wars.\"",
  "megapixels": "1",
  "outputCount": 1,
  "guidanceScale": 3,
  "loraIntensity": 1,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "acceleratedMode": false,
  "imageAspectRatio": "21:9",
  "externalLoraScale": 1,
  "imageOutputFormat": "webp",
  "inferenceStepCount": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Conclusion

Grievous provides developers with a robust solution for generating custom images with ease. By harnessing the power of advanced inpainting and image-to-image techniques, you can create high-quality visuals tailored to your specific needs. The flexibility of input parameters allows for a wide range of applications, from artistic endeavors to professional marketing materials. 

Ready to take your visual content to the next level? Explore the capabilities of Grievous and start generating stunning images today!