Enhance Your Images with Flux Fill’s Inpainting Action

26 Apr 2025
Enhance Your Images with Flux Fill’s Inpainting Action

In the world of digital creativity, the ability to manipulate and enhance images is invaluable. The "Flux Fill Dev" service offers powerful Cognitive Actions that enable developers to integrate advanced image inpainting capabilities into their applications. With the use of the FLUX.1 Fill model, you can seamlessly edit and extend images while preserving their original context. This opens up a realm of possibilities for creative tools, allowing for quick edits, restorations, and enhancements without the hassle of manual interventions.

Whether you're building an application for graphic designers, social media platforms, or e-commerce, the ability to inpaint images can greatly enhance user experience. Imagine being able to remove unwanted objects from photos, fill in missing parts of a picture, or creatively expand an image to fit specific dimensions—all with just a few API calls.

Prerequisites

To get started, you will need a Cognitive Actions API key and a basic understanding of making API calls.

Perform Image Inpainting with FLUX.1 Fill

The "Perform Image Inpainting with FLUX.1 Fill" action allows you to edit images by specifying new content in selected areas while keeping the surrounding context intact. This is particularly useful for applications that require high-quality image modifications.

Input Requirements

To utilize this action, you will need to provide the following inputs:

  • image: The URI of the image to be inpainted.
  • prompt: A textual description guiding the inpainting process (e.g., "a spaceship").
  • mask: A black-and-white image indicating which areas to inpaint (black areas are preserved, white areas are modified).
  • guidance: A numeric value indicating how closely the output should adhere to the prompt.
  • imageFormat: The desired output format (e.g., "webp", "jpg", "png").
  • imageQuality: The quality of the output image.
  • inferenceSteps: The number of steps for denoising during generation.
  • numberOfOutputs: The number of images to generate.
  • approximateMegapixels: The size of the generated image in megapixels.
  • safetyCheckerDisabled: A boolean to disable the safety checker for generated images.

Expected Output

The output will be a URI pointing to the inpainted image, which can be used directly in your application.

Use Cases for this Action

  • Content Creation: Ideal for apps designed for graphic artists who need to quickly modify images without starting from scratch.
  • E-commerce: Enhance product images by removing backgrounds or filling missing details, making them more appealing to customers.
  • Social Media: Allow users to customize their photos by adding elements or removing distractions easily.
  • Restoration: Use the inpainting action to restore old or damaged photographs by filling in missing parts based on context.
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 = "7381f2ed-ea1d-43b9-830d-75cde3134cb7" # Action ID for: Perform Image Inpainting with FLUX.1 Fill

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "mask": "https://replicate.delivery/pbxt/M0hxLu8a1YBcybWuumSsfoEec8ooer6JZ2fR28vuM1U0CN9m/74b40bb1-364a-461a-bec5-200a38c7bc87.png",
  "image": "https://replicate.delivery/pbxt/M0hxMJeO7wFCMr7QYNZsjRxzHhz6ntlLllMteRQNsRD7f3Nf/flux-fill-dev.webp",
  "prompt": "a spaceship",
  "guidance": 30,
  "imageFormat": "webp",
  "imageQuality": 80,
  "inferenceSteps": 28,
  "numberOfOutputs": 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 Flux Fill Dev service provides a robust solution for image inpainting, empowering developers to create applications that offer advanced image editing capabilities. With its ease of use and high-quality output, integrating this action can significantly enhance the functionality of your creative tools. As you explore the potential of image inpainting, consider how it can transform user experiences in your applications. Start building today and unlock the full potential of your images!