Effortless Image Generation with Inpainting Using Puma

26 Apr 2025
Effortless Image Generation with Inpainting Using Puma

In the ever-evolving landscape of image generation, Puma stands out as a powerful service that leverages advanced inpainting techniques. This platform allows developers to generate stunning images by customizing various parameters such as aspect ratio, image quality, and inference steps. Whether you're looking to create unique artwork, enhance existing images, or automate content creation, Puma simplifies the process, saving you both time and effort.

Common use cases for Puma's image generation capabilities include creating digital content for marketing, designing custom graphics for web applications, and generating images for social media campaigns. The ability to fine-tune outputs with specific prompts and parameters makes Puma an essential tool for developers seeking to harness the power of AI-driven image creation.

Prerequisites

To get started with Puma, you'll need a Cognitive Actions API key and a basic understanding of making API calls. This will enable you to integrate the image generation capabilities into your applications seamlessly.

Generate Image with Inpainting

The "Generate Image with Inpainting" action allows you to create images using advanced inpainting techniques. This operation is particularly useful for transforming existing images or generating entirely new visuals based on descriptive prompts. With customizable parameters, you can influence the outcome significantly, ensuring that the generated images meet your specific needs.

Input Requirements

The input for this action requires a JSON object that includes at least a prompt. Additional optional parameters include:

  • mask: An image mask for inpainting mode (if provided, aspect ratio, width, and height inputs are ignored).
  • image: An input image for transformation (if provided, aspect ratio, width, and height inputs are ignored).
  • model: Choose between "dev" or "schnell" for different inference qualities.
  • width and height: Specify dimensions if using a custom aspect ratio.
  • goFast: Enable faster predictions with optimized models.
  • numOutputs: Define how many images to generate (1 to 4).
  • aspectRatio: Select from predefined ratios or set a custom one.
  • outputFormat: Choose from formats like webp, jpg, or png.
  • guidanceScale, outputQuality, promptStrength, among others, to further refine the output.

Example input could look like this:

{
  "model": "dev",
  "prompt": "puma, sitting, white background",
  "extraLora": "sunday-film/slumberland-props-2",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "2:3",
  "outputFormat": "jpg",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 0.7,
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Expected Output

The output will be a set of generated images based on the input parameters. Each image will be returned as a URL link, allowing for easy integration and display in your applications.

Example output might include:

  • https://assets.cognitiveactions.com/invocations/.../image1.jpg
  • https://assets.cognitiveactions.com/invocations/.../image2.jpg
  • https://assets.cognitiveactions.com/invocations/.../image3.jpg
  • https://assets.cognitiveactions.com/invocations/.../image4.jpg

Use Cases for this Specific Action

  1. Creative Content Generation: Automatically generate unique images for blog posts, articles, or social media, reducing the time spent on graphic design.
  2. Product Visualization: Enhance product images by modifying backgrounds or features, making them more appealing for e-commerce platforms.
  3. Artistic Projects: Create original artwork or illustrations by providing descriptive prompts, ideal for artists and designers looking for inspiration or drafts.
  4. Game Development: Generate assets for character designs or environments based on specific requirements, streamlining the development process.
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 = "f02aa2bf-30cd-4018-8e01-64ed454a1667" # 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 = {
  "model": "dev",
  "prompt": "puma, sitting, white background",
  "extraLora": "sunday-film/slumberland-props-2",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "2:3",
  "outputFormat": "jpg",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 0.7,
  "promptStrength": 0.8,
  "numInferenceSteps": 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

Puma's "Generate Image with Inpainting" action offers an intuitive and flexible solution for developers looking to create high-quality images quickly. By leveraging customizable parameters, you can tailor the output to fit your specific needs, whether for marketing, artistic, or development purposes.

Next steps could involve experimenting with different prompts and settings to discover the full potential of Puma. As you integrate this powerful tool into your applications, you'll find that creating stunning visuals has never been easier.