Create Stunning Images with Inpainting Using Pbub

26 Apr 2025
Create Stunning Images with Inpainting Using Pbub

In the world of digital creativity, the ability to generate high-quality images can significantly enhance projects in art, marketing, and content creation. Pbub offers powerful Cognitive Actions that enable developers to generate images with inpainting techniques, allowing for remarkable image customization and styling. This functionality not only simplifies the image creation process but also empowers developers to produce visually appealing results quickly and efficiently.

The inpainting action supports various scenarios, such as enhancing existing images, creating unique art pieces, or even generating content for social media. By leveraging parameters like aspect ratio, resolution, and output quality, developers can tailor the image generation process to meet their specific needs. Whether you are looking to create an entirely new visual from scratch or modify an existing one, Pbub's inpainting capabilities provide a versatile solution.

Prerequisites

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

Generate Image with Inpainting

This operation generates an image using advanced inpainting techniques. It allows for image-to-image transitions and offers control over various parameters, ensuring that developers can create images that fit their requirements. The action provides two inference models: 'dev', which delivers detailed results, and 'schnell', which prioritizes speed.

Input Requirements

To use this action, the following inputs are required:

  • Prompt: A descriptive text that guides the image generation process.
  • Mask: (optional) A URI of the image mask for inpainting mode.
  • Image: (optional) A URI of the input image for modifications.
  • Width & Height: (optional) Custom dimensions for the generated image (only if aspect_ratio is set to 'custom').
  • Output Count: The number of images to generate (1-4).
  • Additional Parameters: Options for model weights, LoRA intensity, aspect ratio, quality, and more.

Example Input:

{
  "prompt": "Pbub redhead girl 17 years old taking a photo holding a crumpled piece of paper.",
  "outputCount": 3,
  "loraIntensity": 1,
  "inferenceModel": "dev",
  "imageAspectRatio": "2:3",
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 90,
  "inferenceStepCount": 28,
  "img2imgPromptStrength": 0.8,
  "diffusionGuidanceScale": 3.5,
  "additionalLoraIntensity": 1
}

Expected Output

The output consists of a set of generated images based on the provided prompt and parameters. Each image URL will point to the newly created visuals, which can be utilized across various applications.

Example Output:

  • https://assets.cognitiveactions.com/invocations/1278ef77-a3b6-4986-b5e6-959d35af4186/ad3ec8b9-bf92-4fcd-8300-d19ca2b19421.jpg
  • https://assets.cognitiveactions.com/invocations/1278ef77-a3b6-4986-b5e6-959d35af4186/80f10cc9-c493-42f5-9030-8c48e8e79210.jpg
  • https://assets.cognitiveactions.com/invocations/1278ef77-a3b6-4986-b5e6-959d35af4186/64fc32a0-c972-492a-85cb-1183cbbf8c64.jpg

Use Cases for this Specific Action

  • Artistic Creation: Use the inpainting action to create unique artworks by blending various styles and elements.
  • Marketing Materials: Generate eye-catching images for advertisements or social media campaigns that require specific visual themes.
  • Content Enhancement: Modify existing images to fit new narratives or branding guidelines, making it easier to refresh content without starting from scratch.
  • Prototyping: Quickly create visual prototypes for apps, websites, or presentations, allowing for rapid feedback and iteration.
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 = "f18ae036-afb8-429b-a95b-0f1f52669f8b" # 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": "Pbub redhead girl 17 years old taking a photo holding a crumpled piece of paper. On the paper written in pen \"age 17\" and \"2-5-2007\" and \"luna88luvgood\" and \"10-11-2024\"",
  "outputCount": 3,
  "loraIntensity": 1,
  "inferenceModel": "dev",
  "imageAspectRatio": "2:3",
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 90,
  "inferenceStepCount": 28,
  "img2imgPromptStrength": 0.8,
  "diffusionGuidanceScale": 3.5,
  "additionalLoraIntensity": 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

Pbub's inpainting capabilities provide developers with a robust tool for image generation, enabling the creation of high-quality visuals tailored to specific needs. With its flexibility and ease of use, this action is ideal for a variety of applications, from artistic endeavors to marketing strategies.

To harness the full potential of Pbub, experiment with the various parameters and explore how they can enhance your projects. Start integrating these Cognitive Actions today to elevate your image generation capabilities!