Create Stunning Images with Chadmeme's Inpainting Action

27 Apr 2025
Create Stunning Images with Chadmeme's Inpainting Action

Chadmeme is an innovative service designed for developers seeking to harness the power of AI for image creation and manipulation. With its advanced Cognitive Actions, Chadmeme simplifies the process of generating images based on text prompts, enabling a seamless integration into various applications. This can significantly enhance user experiences by providing customized and dynamic visual content on-demand.

The primary action, "Generate Image with Inpainting," allows developers to create unique images using textual descriptions while also offering the flexibility to modify existing images through inpainting techniques. This feature is particularly useful for applications in marketing, gaming, and creative industries, where personalized visuals can drive engagement and creativity.

Prerequisites

To get started with Chadmeme, you'll need a valid Cognitive Actions API key and a basic understanding of making API calls.

Generate Image with Inpainting

The "Generate Image with Inpainting" action utilizes either the 'schnell' or 'dev' model to produce images based on a provided text prompt. This action not only generates new images but also supports image-to-image transformations, allowing for detailed customizations through various parameters.

Purpose

This action addresses the need for tailored visual content that aligns with specific themes or concepts, making it ideal for designers, marketers, and content creators who require unique imagery without extensive manual effort.

Input Requirements

The input for this action is structured as a JSON object and includes several fields:

  • Prompt (required): The text description guiding the image generation, e.g., "chadmeme male cooks. White background, minimalistic, draw with pen."
  • Image (optional): A URI linking to an input image for inpainting.
  • Mask (optional): A URI for an image mask, enabling targeted modifications.
  • Width and Height (optional): Dimensions of the generated image, applicable if a custom aspect ratio is selected.
  • Model Type (optional): Choose between 'dev' for detailed outputs or 'schnell' for faster generation.
  • Additional parameters like numOutputs, guidanceScale, and outputQuality can also be specified for finer control.

Expected Output

The output will consist of one to four generated images in the specified format (webp, jpg, png). Each output image will reflect the input prompt, capturing the desired elements and styles.

Use Cases for this specific action

  • Marketing Campaigns: Create promotional visuals tailored to specific themes or products, enhancing brand engagement.
  • Gaming Development: Generate unique character designs or environments based on descriptive prompts, streamlining the creative process.
  • Art and Design Projects: Enable artists to visualize concepts quickly, experimenting with different styles and compositions without starting from scratch.
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 = "303b2e52-1312-4407-a806-d93d5e921a38" # Action ID for: Generate Image with Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 512,
  "height": 512,
  "prompt": "chadmeme male cooks. White background, minimalistic, draw with pen",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 4,
  "imageFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 80,
  "extraLoraScale": 0.8,
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "numInferenceSteps": 40
}

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

Chadmeme's image generation capabilities through the "Generate Image with Inpainting" action provide developers with a powerful tool to create customized visuals effortlessly. By leveraging AI-driven technology, you can enhance your applications with engaging imagery, streamline creative processes, and offer users a unique experience.

As a next step, consider integrating this action into your projects to see firsthand how it can transform the way you approach image creation and manipulation.