Create Stunning Images with Florentino's Inpainting Action

26 Apr 2025
Create Stunning Images with Florentino's Inpainting Action

Florentino provides a powerful set of Cognitive Actions designed to simplify and enhance image generation. One of its standout features is the ability to generate images using inpainting techniques, which allows developers to create customized visuals that meet specific requirements. With options to adjust attributes like width, height, and aspect ratio, as well as select from different inference models, this action is perfect for various applications. Whether you're looking to create unique graphics for websites, develop marketing materials, or simply explore the creative potential of AI, Florentino's inpainting capabilities can significantly speed up your workflow and enrich your projects.

Prerequisites

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

Generate Image with Inpainting

The "Generate Image with Inpainting" action allows for the generation of images by utilizing advanced inpainting techniques. This operation is particularly beneficial for scenarios where customization is key, enabling users to modify various attributes of the generated images while maintaining high quality.

Input Requirements:

  • Prompt: A text prompt for generating the image (e.g., "Make an image of a computer screen in the style of CDMX").
  • Mask (optional): A URI for an image mask used in inpainting mode.
  • Image (optional): A URI for an input image for image-to-image or inpainting mode.
  • Width & Height (optional): Dimensions for the generated image in pixels (only applicable if aspect_ratio is set to custom).
  • Model Weights (optional): URI to load LoRA weights from various repositories.
  • Inference Model: Choose between 'dev' or 'schnell' for different inference speeds.
  • Output Format: Specify the format of the output images (e.g., webp, jpg, png).
  • Additional parameters: Include settings for guidance scale, output quality, and more.

Expected Output: The output will be a URI link to the generated image, which can be used directly in applications or shared as needed.

Use Cases for this specific action:

  1. E-commerce: Generate product images with specific customizations to match branding.
  2. Content Creation: Create unique visuals for blogs or social media posts that stand out from stock images.
  3. Game Development: Design assets or backgrounds by modifying existing images with inpainting techniques.
  4. Personal Projects: Explore artistic expressions by generating images based on creative prompts and styles.
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 = "22573cbe-efc6-40a1-8d0d-1f198bf0b1ce" # 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 = {
  "prompt": "Make an image of a computer screen in the style of CDMX",
  "loraIntensity": 1.17,
  "inferenceModel": "dev",
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageGuidanceScale": 3.5,
  "imageOutputQuality": 80,
  "inferenceStepCount": 28,
  "additionalLoraIntensity": 0.8
}

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

Florentino's "Generate Image with Inpainting" action is a versatile tool that empowers developers to create customized images quickly and efficiently. With its robust features and flexibility, it opens up a world of possibilities for various applications, from marketing to creative projects. To make the most of this action, consider experimenting with different parameters and explore the potential of AI-driven image generation in your development workflows.