Create Stunning Images with Mm Brsh's Inpainting Action

26 Apr 2025
Create Stunning Images with Mm Brsh's Inpainting Action

In the digital age, the ability to generate compelling visuals quickly and efficiently is essential for developers and content creators alike. The "Mm Brsh" service offers a powerful Cognitive Action that allows you to generate images using an advanced inpainting mode. This functionality enables you to create customized visuals that meet your specific needs by integrating parameters such as masks, aspect ratios, and quality settings. By utilizing this action, you can enhance the realism of your images while also optimizing performance based on your requirements.

Imagine the possibilities: whether you're looking to create unique artwork, generate content for marketing materials, or enhance visual storytelling in applications, the inpainting capabilities of Mm Brsh can help you achieve your goals faster and with greater fidelity.

Prerequisites

To get started with the Mm Brsh Cognitive Actions, you will need an API key and a basic understanding of making API calls.

Generate Image with Inpainting Mode

This action allows you to generate images by either using an existing image as a base or creating entirely new visuals through inpainting. You can refine your outputs by controlling various parameters, including the model used for inference, the number of outputs, and the image quality.

Purpose

The primary goal of this action is to enable developers to create high-quality images tailored to specific prompts, ensuring that outputs align closely with the envisioned concept or artistic direction.

Input Requirements

To utilize this action, you must provide a structured input that includes the following key components:

  • Prompt: A descriptive text that outlines what the generated image should depict.
  • Image (optional): An existing image used for inpainting.
  • Mask (optional): Defines areas of the image to modify or retain.
  • Model: Choose between 'dev' for optimal performance or 'schnell' for faster results.
  • Aspect Ratio: Specify the desired aspect ratio for the image.
  • Output Count: Indicate how many images you want to generate.

Expected Output

The output will be a set of image URLs generated based on the parameters you provided. Each image will reflect the prompt and any modifications specified through masking or other settings.

Use Cases for this Specific Action

  • Art Creation: Ideal for artists and designers looking to generate unique artwork based on specific themes or styles.
  • Content Generation: Perfect for marketers who need tailored visuals for campaigns or social media posts.
  • Prototyping: Useful for developers creating mockups or prototypes that require quick visual iterations.
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 = "4be94fb4-083a-4417-8279-2c32b2549201" # Action ID for: Generate Image with Inpainting Mode

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/MYEkMcybmbifDGaG3n5KRhLYGBi5cxjCemHp19iyZ3KSfwMI/b02d9a05b2ae2f52b2dc17cf78b0a0e8.jpg",
  "model": "dev",
  "prompt": "A surreal, airbrush-style digital artwork illustration a lone robot draped in flowing orange fabric against a monochromatic orange background. The robot head is a reflective, spherical mirror that subtly captures the environment’s reflection. The glossy cloak has a softly contoured, almost metallic sheen, and the overall image has a slightly grainy or textured finish. The warm color palette, coupled with the faceless mirrored orb, imparts a futuristic, enigmatic atmosphere.",
  "megapixels": "1",
  "outputCount": 2,
  "guidanceScale": 3,
  "mainLoraScale": 1.06,
  "enableFastMode": false,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "inferenceStepCount": 28,
  "imagePromptStrength": 0.8,
  "extraLoraScalingFactor": 1
}

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 inpainting capabilities of Mm Brsh empower developers to create stunning images tailored to their unique needs, whether for artistic endeavors, marketing, or application development. By leveraging the flexibility of this Cognitive Action, you can streamline your creative workflow and produce high-quality visuals that resonate with your audience.

To explore further, consider integrating this action into your projects and experiment with different parameters to discover the full potential of image generation.