Mastering Image Generation with the cgdougm/olipop-can-grape Actions

24 Apr 2025
Mastering Image Generation with the cgdougm/olipop-can-grape Actions

In today's rapidly advancing tech landscape, AI-driven capabilities are transforming how we create and interact with digital content. The cgdougm/olipop-can-grape spec provides a powerful set of Cognitive Actions designed to generate images through advanced techniques like inpainting. These pre-built actions allow developers to leverage AI for creative projects, enabling customization and flexibility in image generation.

In this blog post, we'll explore how to integrate the Generate Image with Inpainting action into your applications, providing clear guidance on setup and implementation.

Prerequisites

Before diving into the integration, ensure you have the following:

  • API Key: You'll need an API key for the Cognitive Actions platform to authenticate your requests. This key should be included in the request headers.
  • Development Environment: A working environment set up for making HTTP requests (Python is used in our examples).

Authentication typically involves passing your API key in the request headers, allowing you to access the Cognitive Actions service securely.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using an image-to-image or inpainting technique. This action supports custom dimensions, model selection, and prompt strength for detailed customization. With options for output quality and format, developers have the flexibility to generate images that fit specific requirements.

Input

The input to this action is a JSON object with the following schema:

{
  "prompt": "string",
  "mask": "uri",
  "seed": "integer",
  "image": "uri",
  "model": "string",
  "width": "integer",
  "height": "integer",
  "loraScale": "number",
  "megapixels": "string",
  "aspectRatio": "string",
  "outputFormat": "string",
  "guidanceScale": "number",
  "outputQuality": "integer",
  "additionalLora": "string",
  "promptStrength": "number",
  "numberOfOutputs": "integer",
  "additionalLoraScale": "number",
  "enableFastGeneration": "boolean",
  "additionalLoraWeights": "string",
  "numberOfInferenceSteps": "integer",
  "disableImageSafetyChecker": "boolean"
}

Example Input:

{
  "model": "dev",
  "prompt": "OLIPOP_GRAPE In a studio lighting setup, seamless backdrop in an ochre color, on the can is the word, GRAPE-ISH in a retro font from the 70s",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "outputFormat": "jpg",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 28
}

Output

Upon successful execution, the action returns an array of URLs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/91345c66-6ad3-4bf4-89f1-aaf06485aee5/db111feb-94b8-487f-8468-3064b91dda29.jpg",
  "https://assets.cognitiveactions.com/invocations/91345c66-6ad3-4bf4-89f1-aaf06485aee5/e132918f-490d-4bf1-9df7-d7da0c8f16df.jpg",
  "https://assets.cognitiveactions.com/invocations/91345c66-6ad3-4bf4-89f1-aaf06485aee5/afb581ce-4a98-4548-b615-f18b51eb7f04.jpg",
  "https://assets.cognitiveactions.com/invocations/91345c66-6ad3-4bf4-89f1-aaf06485aee5/2c507a41-28d7-42df-8a1c-487def50d43f.jpg"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to call the Generate Image with Inpainting action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "49b87183-a090-4db8-85ef-22be5658b672"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "OLIPOP_GRAPE In a studio lighting setup, seamless backdrop in an ochre color, on the can is the word, GRAPE-ISH in a retro font from the 70s",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "outputFormat": "jpg",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "additionalLoraScale": 1,
    "numberOfInferenceSteps": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this code snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action ID for the Generate Image with Inpainting action is provided, and the input payload is constructed as per the action's requirements.
  • The response is processed to display the generated image URLs.

Conclusion

The cgdougm/olipop-can-grape Cognitive Actions provide a remarkable way to integrate AI-powered image generation into your applications. By leveraging the Generate Image with Inpainting action, developers can create customized images tailored to specific needs effortlessly.

Consider exploring other potential use cases, such as enhancing content creation workflows, generating marketing materials, or even creating unique artwork. The possibilities are vast, and with the right implementation, you can harness the power of AI in your projects today!