Create Stunning Inpainted Images Effortlessly with Pbm

25 Apr 2025
Create Stunning Inpainted Images Effortlessly with Pbm

The Pbm service offers powerful Cognitive Actions designed to enhance your image generation capabilities, particularly through its ability to create high-quality inpainted images. This functionality allows developers to leverage customizable prompts and inference models, making it easier and faster to generate visually appealing content. With adjustable parameters like image aspect ratio, output quality, and fast mode options, you can tailor the output to meet your specific needs.

Common use cases for the Pbm service include generating professional profile pictures, creating marketing visuals, or even enhancing artistic projects. Whether you're looking to restore parts of an image, create a unique piece of art, or simply experiment with visual content, Pbm's inpainting capabilities can significantly simplify the process.

Prerequisites

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

Generate Inpainted Image

The "Generate Inpainted Image" action allows you to create high-quality images by filling in missing or corrupted sections of an image using customizable prompts. This action is particularly useful for restoring images, generating creative visuals, or producing tailored content that meets specific artistic requirements.

Input Requirements

To use this action, you will need to provide a prompt, which serves as a guiding description of the desired output. Additionally, you can specify parameters such as an image mask, a seed for reproducibility, and the model type (either 'dev' for detailed generation or 'schnell' for faster results).

Expected Output

The output will include one or more inpainted images based on your specifications. The images are generated in the desired format and quality, ready for immediate use.

Use Cases for this specific action

  • Profile Picture Generation: Create a professional-looking profile image that meets specific requirements, such as background and attire.
  • Marketing Material: Generate eye-catching visuals tailored to a brand's identity.
  • Artistic Projects: Experiment with inpainting for creative artworks, allowing for greater artistic freedom and unique results.

```python
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 = "09b516b4-dfc5-4798-8bc9-700597aa21a6" # Action ID for: Generate Inpainted Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "goFast": false,
  "height": 901,
  "prompt": "PBM genera una imagen hiperrealista de mí para mi perfil de LinkedIn, que sea una foto profesional, en la que esté sonriendo, no se me noten las ojeras ni arrugas en el párpado bajo, con un peinado pixie moderno, con gafas, sin reflejos en las gafas, discretamente maquillada, de pie,con los brazos cruzados, chaqueta, fondo neutro, mirando a la cámara, pecho grande, complexión corporal grande, con gafas. que se me vea medio cuerpo en perspectiva 3/4. COLOR AZUL MARINO BLAZER Y CAMISETA BLANCA. SONRIENDO. FONDO LISO NEUTRO",
  "mainLoraScale": 1,
  "imageMegapixels": "1",
  "numberOfOutputs": 4,
  "promptIntensity": 0.8,
  "imageAspectRatio": "1:1",
  "guidanceIntensity": 3,
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 28
}

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 Pbm service's inpainting capabilities provide developers with a robust tool for generating high-quality images tailored to specific needs. With customizable prompts, adjustable parameters, and support for various output formats, you can easily create stunning visuals for any application. As you explore the potential of Pbm, consider the diverse use cases it enables, from professional imagery to creative projects. Start integrating these Cognitive Actions today to enhance your image generation workflow!