Create Stunning Images with Pdp's Inpainting and Aspect Ratio Customization

26 Apr 2025
Create Stunning Images with Pdp's Inpainting and Aspect Ratio Customization

In the realm of digital creativity, generating high-quality images that meet specific requirements can often be a daunting task. The Pdp service simplifies this process with its advanced Cognitive Actions, particularly focused on image generation. One of the standout features is the ability to generate images using inpainting techniques while allowing for custom aspect ratios. This enables developers to create visually striking images tailored to their needs, whether for marketing materials, social media, or artistic projects.

Imagine being able to produce sharp, high-detail images that match the exact specifications you require, all while optimizing for speed and quality. With Pdp, you can easily integrate image generation capabilities into your applications, enhancing user experiences and streamlining workflows.

Prerequisites

Before diving into the integration of Pdp's Cognitive Actions, ensure you have your API key handy and a basic understanding of making API calls.

Generate Image with Inpainting and Custom Aspect Ratio

This action is designed to generate high-quality images using either image-to-image or inpainting techniques. It allows you to customize image dimensions, quality, and even the model used for generation, ensuring that your output aligns perfectly with your project’s requirements.

Input Requirements

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

  • Prompt: A descriptive text that guides the image generation process.
  • Mask (optional): An image mask for inpainting mode, which overrides width and height if provided.
  • Image (optional): An input image for transformation or inpainting.
  • Width and Height: Specify dimensions if using a custom aspect ratio.
  • Aspect Ratio: Choose from predefined ratios or set a custom one.
  • Output Count: Define how many images you want to generate.
  • Image Format: Choose the format for the output images (e.g., webp, jpg, png).
  • Quality: Set the quality level of the output images.
  • Lora Scale and Additional Lora Scale: Control the application strength of LoRA weights.
  • Inference Model: Select between different models for optimized performance.
  • Guidance Scale: Adjust the guidance level for the generation process.

Expected Output

The output will be a high-quality image generated based on your input specifications, delivered in the chosen format. The result will match the prompt and other parameters provided, allowing for a seamless integration into your application.

Use Cases for this Specific Action

  • Marketing and Advertising: Generate tailored images for campaigns that require specific themes or styles.
  • E-commerce: Create product images that meet exact dimensions and quality standards.
  • Social Media: Design eye-catching visuals that fit perfectly within platform specifications.
  • Artistic Projects: Experiment with inpainting to create unique artworks or modify existing images.
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 = "47decbf0-7048-4da1-9c20-8ca1f659d1b0" # Action ID for: Generate Image with Inpainting and Custom Aspect Ratio

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "A professional studio portrait of DIGZ, is totaly bold, is more on the skinny side, stay as close to the original pictures as possible, facing the camera with a confident and approachable expression. Wearing a business suit, with soft and natural lighting. The background is a clean, neutral gradient . The image has high detail, sharp focus, and a smooth depth of field, ensuring a polished and professional aesthetic. DSLR-level quality, cinematic lighting, and realistic skin texture.",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 80,
  "guidanceScale": 3,
  "enableFastMode": false,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "additionalLoraScale": 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

Pdp's image generation capabilities open up a world of possibilities for developers looking to enhance their applications with high-quality visuals. By utilizing the inpainting and custom aspect ratio features, you can create stunning images that meet your specific needs. Whether for marketing, e-commerce, or creative projects, the flexibility and optimization offered by Pdp make it an invaluable tool in your development arsenal.

As a next step, consider experimenting with different prompts and settings to discover the full potential of Pdp's Cognitive Actions in your projects.