Create Stunning Images with Heuserfar's Image Generation Actions

26 Apr 2025
Create Stunning Images with Heuserfar's Image Generation Actions

In today's digital landscape, the ability to generate high-quality images quickly and efficiently is invaluable for developers and designers alike. Heuserfar offers a powerful Cognitive Action that allows you to generate styled images with optional inpainting capabilities, making it easier than ever to create visually appealing content. With customizable options like aspect ratio, dimensions, and advanced stylistic effects, this action is designed to meet various creative needs, whether for marketing materials, social media graphics, or digital artwork.

Imagine being able to transform a simple text prompt into a stunning image with just a few API calls. This not only saves time but also enables you to explore creative possibilities that may have been previously unattainable. The flexibility to choose between detailed or fast generation models further enhances the usability of Heuserfar, allowing you to optimize for quality or speed based on your project requirements.

Generate Image with Style and Inpainting

The "Generate Image with Style and Inpainting" action is designed to create aesthetically pleasing images based on user-defined prompts. This functionality is particularly useful for artists, marketers, and content creators looking to generate unique visuals tailored to specific themes or concepts.

Input Requirements

To utilize this action, you need to provide a structured input including:

  • prompt (string): A description of the image you wish to generate. Including specific trigger words can help activate trained styles or objects.
  • mask (string, optional): An image mask for inpainting mode.
  • image (string, optional): An input image for modifications.
  • width (integer, optional): The width of the generated image (if aspect_ratio is set to custom).
  • height (integer, optional): The height of the generated image (if aspect_ratio is set to custom).
  • numOutputs (integer): The number of images to generate (1-4).
  • inferenceModel (string): Choose between 'dev' for detailed generation or 'schnell' for faster results.

Expected Output

The action returns an array of image URLs, where each URL points to a generated image that corresponds to the provided prompt and parameters.

Use Cases for this Specific Action

  • Marketing Campaigns: Quickly generate eye-catching visuals for advertisements or social media posts that align with your brand's aesthetic.
  • Digital Art Creation: Artists can leverage this action to experiment with different styles and concepts, producing unique artwork without the need for extensive manual effort.
  • Content Generation: Bloggers and content creators can create custom images to complement their articles, enhancing engagement and visual appeal.
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 = "0c9bb4a6-ddd9-46c2-a89d-7e68a2c93a52" # Action ID for: Generate Image with Style and Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "goFast": false,
  "prompt": "a RYBOJSI eccentric king style illustration of Heusman man with a crown sitting on a mighty throne, holding a beer, looking directly into the camera , smiling",
  "extraLora": "https://huggingface.co/alexanderburuma/royalllleiei/resolve/main/lora.safetensors",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 50
}

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

Heuserfar's image generation action offers a versatile solution for creating stunning visual content quickly and efficiently. By leveraging customizable parameters and model options, developers can cater to a wide range of use cases, from marketing materials to personal art projects. As you explore the capabilities of this action, consider how it can enhance your workflow and inspire creativity in your projects. The next step is simple: integrate this action into your applications and start generating remarkable images today!