Create Stunning Images with Inpainting Using Pistachio 1

26 Apr 2025
Create Stunning Images with Inpainting Using Pistachio 1

In the world of digital content creation, the demand for high-quality images has never been greater. With the Pistachio 1 service, developers can harness the power of advanced image generation techniques through its Cognitive Actions. One of the standout features is the ability to generate images with inpainting, allowing for sophisticated image-to-image transformations and the enhancement of existing visuals. This functionality not only simplifies the creative process but also accelerates development timelines, enabling rapid prototyping and deployment of visually engaging content.

Common use cases for this action include creating unique artwork, enhancing product images for e-commerce, or generating variations of existing graphics for marketing. Whether you’re a game developer looking to create immersive environments or a digital artist aiming to refine your portfolio, Pistachio 1’s image generation capabilities provide a versatile toolkit for any developer.

Prerequisites

To get started with the Pistachio 1 Cognitive Actions, you will need an API key and a basic understanding of making API calls.

Generate Image with Inpainting

The Generate Image with Inpainting action is designed to produce images through an advanced method that supports both image-to-image transformations and inpainting. This action allows users to utilize prompt guidance and optional mask images to create high-quality or rapid image outputs. It also supports various output formats and configurations, including LoRA intensity adjustments and safety checkers.

Input Requirements

  • Prompt: A text prompt that guides the image generation process. This is essential for the action to understand what kind of image to generate.
  • Image: A URI of an input image for generating variants or inpainting, which disables aspect ratio, width, and height inputs.
  • Mask: A URI of an image mask for inpainting mode, which overrides aspect ratio, width, and height inputs.
  • Width and Height: Specifies the dimensions of the generated image when using a custom aspect ratio.
  • Model Type: Choose between 'dev' for optimized performance or 'schnell' for faster generation.
  • Output Count: Determine the number of images to generate, ranging from 1 to 4.
  • Image Quality: Set the quality level of the output images.
  • Prompt Intensity and Guidance Strength: Control the strength and guidance of the generation process.
  • Image Aspect Ratio: Define the desired aspect ratio for the generated image.
  • Additional parameters: Such as LoRA weights, fast prediction settings, and safety checker options.

Expected Output

The action produces a URI pointing to the generated image, which can be in formats like webp, jpg, or png. For example, a typical output might look like:

  • https://assets.cognitiveactions.com/invocations/a45627d0-60db-453b-b08d-09a66508c943/aaf37002-2859-4b62-9e5d-c762b3c232af.webp

Use Cases for this Specific Action

  • Art Creation: Artists can generate unique pieces of art based on specific prompts, allowing for endless creativity.
  • E-commerce: Businesses can enhance product images by inpainting certain areas, making them more appealing to customers.
  • Marketing Materials: Marketers can create visually compelling graphics that align with their campaigns, using existing images as a base for modifications.

```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 = "b45697ba-8b80-4ce1-8617-0addd7229f36" # 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": "pistachio",
  "modelType": "dev",
  "outputCount": 1,
  "imageQuality": 90,
  "promptIntensity": 0.8,
  "guidanceStrength": 3.5,
  "imageAspectRatio": "1:1",
  "mainLoraStrength": 1,
  "imageOutputFormat": "webp",
  "inferenceStepCount": 28,
  "additionalLoraStrength": 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
Pistachio 1’s image generation capabilities empower developers to create stunning visuals efficiently and effectively. By leveraging the Generate Image with Inpainting action, you can streamline your creative processes and produce high-quality images tailored to your specific needs. Whether for artistic expression, commercial use, or marketing purposes, the flexibility and power of this action open up new possibilities. Start integrating Pistachio 1 into your projects today and unlock the potential of advanced image generation.