Seamlessly Edit and Extend Images with FLUX.1 Fill Pro Cognitive Actions

In the world of digital content creation, the ability to manipulate images effectively can set your work apart. The FLUX.1 Fill Pro Cognitive Actions from the black-forest-labs/flux-fill-pro spec provide developers with robust tools for image inpainting and outpainting. This set of pre-built actions allows you to remove unwanted elements, add new features, or expand canvases while preserving natural lighting, perspective, and overall context.
By integrating these actions into your applications, you can enhance user experiences, create captivating visuals, and streamline workflows.
Prerequisites
To get started with the FLUX.1 Fill Pro Cognitive Actions, you'll need:
- An API key for the Cognitive Actions platform, which you will use for authentication.
- Basic familiarity with making HTTP requests and handling JSON data.
- A development environment set up with Python if you wish to use the provided examples.
Authentication is typically handled by including your API key in the request headers, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Edit and Extend Images with FLUX.1 Fill Pro
This action enables you to perform state-of-the-art image editing using inpainting and outpainting techniques. It is particularly useful for tasks such as removing specific objects, adding new elements, or enlarging images while maintaining their quality.
Input
The input schema for this action requires the following fields:
- image (required): The base image to be modified, which can include an alpha mask. Supported formats are jpeg, png, gif, or webp.
- prompt (required): A text prompt guiding the image generation process.
- mask (optional): A black-and-white image indicating areas to be inpainted. The mask must match the image size and can be provided as a URL.
- steps (optional): The number of diffusion steps, ranging from 1 to 50, with a default of 50.
- guidance (optional): A value between 2 and 5 that adjusts adherence to the text prompt versus image quality. Default is 3.
- imageFormat (optional): Specifies the output image format, defaulting to "jpg".
- enhancePrompt (optional): If set to true, the prompt is modified to encourage more creative output.
- contentSafetyLevel (optional): An integer between 1 and 6 that sets the content safety tolerance, defaulting to 2.
Example Input:
{
"mask": "https://replicate.delivery/pbxt/M0gpLCYdCLbnhcz95Poy66q30XW9VSCN65DoDQ8IzdzlQonw/kill-bill-mask.png",
"image": "https://replicate.delivery/pbxt/M0gpKVE9wmEtOQFNDOpwz1uGs0u6nK2NcE85IihwlN0ZEnMF/kill-bill-poster.jpg",
"steps": 50,
"prompt": "movie poster says \"FLUX FILL\"",
"guidance": 3,
"imageFormat": "jpg",
"enhancePrompt": false,
"contentSafetyLevel": 2
}
Output
The output is a URL pointing to the modified image. If successful, the action will return the location of the newly generated image.
Example Output:
https://assets.cognitiveactions.com/invocations/a9896772-ef48-4a5c-88b5-ad881d2ef460/1026e972-dd0a-4383-98ba-fe0a535552d5.jpg
Conceptual Usage Example (Python)
Here’s how you might call this action in Python. This snippet demonstrates how to structure the input payload and send it to the hypothetical Cognitive Actions execution endpoint.
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "2e15f9eb-8f09-4483-97e1-f2acd61a9550" # Action ID for Edit and Extend Images with FLUX.1 Fill Pro
# Construct the input payload based on the action's requirements
payload = {
"mask": "https://replicate.delivery/pbxt/M0gpLCYdCLbnhcz95Poy66q30XW9VSCN65DoDQ8IzdzlQonw/kill-bill-mask.png",
"image": "https://replicate.delivery/pbxt/M0gpKVE9wmEtOQFNDOpwz1uGs0u6nK2NcE85IihwlN0ZEnMF/kill-bill-poster.jpg",
"steps": 50,
"prompt": "movie poster says \"FLUX FILL\"",
"guidance": 3,
"imageFormat": "jpg",
"enhancePrompt": False,
"contentSafetyLevel": 2
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
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: {e.response.text}")
In this code, you will replace the API key and endpoint with your actual credentials. The payload variable contains the necessary parameters to execute the action, and the requests.post method sends the request to the server.
Conclusion
The FLUX.1 Fill Pro Cognitive Actions provide powerful capabilities for image editing and enhancement. By leveraging these tools, developers can create stunning visuals, improve artistic workflows, and offer engaging experiences to users. As you explore the capabilities of these actions, consider integrating them into your applications for a seamless editing experience.