Create Stunning Custom Images Easily with Han

25 Apr 2025
Create Stunning Custom Images Easily with Han

In the evolving world of digital content creation, the ability to generate custom images tailored to your specific needs has become a game-changer. The Han service provides powerful Cognitive Actions that facilitate precise image generation using advanced techniques like inpainting and image-to-image transformation. With the flexibility to control various image properties such as aspect ratio, resolution, and quality, developers can streamline their creative workflows, ensuring efficiency and high-quality outputs.

Imagine using this technology to create unique visuals for marketing campaigns, social media posts, or even artistic projects. Whether you're enhancing existing images or creating entirely new ones, Han's capabilities allow for rapid development and iteration, making it an essential tool for developers and designers alike.

Prerequisites

To get started with Han, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Generate Custom Images with Inpainting

This action empowers users to create custom images by leveraging image-to-image transformation and inpainting techniques. It solves the challenge of generating high-quality visuals that meet specific criteria while allowing for extensive customization.

Input Requirements

The input for this action requires a prompt guiding the image generation process. Additional inputs may include:

  • Mask: A URI for the image mask used in inpainting mode.
  • Image: A URI for the input image if you're transforming an existing image.
  • Width and Height: Specify the dimensions of the output image, applicable only for custom aspect ratios.
  • Image Format: Choose between formats like webp, jpg, or png.
  • Output Count: Set how many images to generate at once (between 1 and 4).
  • Image Quality: Define the quality level for the output image (0-100).
  • Fast Mode: Enable a quicker generation process at the expense of some quality.

Expected Output

The expected output is a URI linking to the generated image, reflecting the characteristics defined in the input.

Use Cases for this Action

  • Marketing: Create tailored images for promotional materials that resonate with specific target audiences.
  • Content Creation: Generate unique visuals for blogs, articles, or social media that stand out.
  • Art Projects: Use inpainting to enhance or alter existing images, adding a personal touch to artistic endeavors.
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 = "7203256c-e43d-468c-9584-c55638d549aa" # Action ID for: Generate Custom Images with Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "Sitting seductively with short hair, colored stockings, colored nails, full body",
  "modelType": "dev",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 90,
  "denoiseStepCount": 28,
  "imageAspectRatio": "1:1",
  "mainLoraIntensity": 1,
  "extraLoraIntensity": 1,
  "inputPromptIntensity": 0.8,
  "diffusionGuidanceIntensity": 3.5
}

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

The Han service's ability to generate custom images through advanced inpainting and transformation techniques offers immense value for developers across various industries. By streamlining the image creation process, it enables faster project turnarounds and higher-quality results.

As you explore the possibilities with Han, consider how these Cognitive Actions can enhance your projects and elevate your creative output. The next steps could involve integrating these actions into your applications, experimenting with different input parameters, and discovering the full potential of custom image generation.