Enhance Your Applications with Image Generation Using galburdragos/photo-ai Cognitive Actions

21 Apr 2025
Enhance Your Applications with Image Generation Using galburdragos/photo-ai Cognitive Actions

In today's digital landscape, the ability to generate and manipulate images programmatically can significantly enhance user experiences and functionalities in applications. The galburdragos/photo-ai API provides a powerful set of Cognitive Actions for image generation, enabling developers to create customized images through inpainting and other techniques. These pre-built actions simplify the integration of advanced image generation capabilities into your applications, saving time and resources while delivering high-quality outputs.

Prerequisites

Before getting started with the Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to access the Cognitive Actions platform. This key is typically included in the request headers for authentication.
  • Setup Environment: Make sure you have a working development environment with Python, along with the requests library installed to handle HTTP requests.

Cognitive Actions Overview

Generate Image Using Inpainting

Description: This operation generates images through inpainting, allowing for customized adjustments such as aspect ratio, width, height, and output format. Leveraging models like 'dev' and 'schnell', it offers options for fast predictions and high-quality outputs.

Category: image-generation

Input

The input schema for this action requires a JSON object with the following fields:

  • prompt (required): A string that describes the image to generate. For example: "portrait of dragos".
  • mask (optional): A URI string for an image mask used in inpainting mode.
  • seed (optional): An integer for reproducibility.
  • image (optional): A URI string for an input image for image-to-image or inpainting mode.
  • width (optional): An integer specifying the width of the generated image (must be between 256 and 1440).
  • height (optional): An integer specifying the height of the generated image (must be between 256 and 1440).
  • imageFormat (optional): The output format of the generated image (default is "webp").
  • outputCount (optional): The number of outputs to generate (default is 1, maximum is 4).
  • enableFastMode (optional): A boolean to optimize for speed (default is false).
  • inferenceModel (optional): Which model to run inference with (default is "dev").
  • imageGuidanceScale (optional): A number that influences the detail of generated images (default is 3).

Example Input:

{
  "prompt": "portrait of dragos",
  "imageFormat": "webp",
  "outputCount": 3,
  "mainLoraScale": 1,
  "enableFastMode": false,
  "inferenceModel": "dev",
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageGuidanceScale": 3,
  "imageOutputQuality": 80,
  "inferenceStepCount": 28,
  "additionalLoraScale": 1,
  "imagePromptStrength": 0.8
}

Output

When the action is executed successfully, it returns an array of URLs pointing to the generated images. For instance:

[
  "https://assets.cognitiveactions.com/invocations/ad7ecfa4-7e54-445b-a4d7-ff38e01e3204/ec8965ae-2b78-4cf2-a83f-af7a721dd170.webp",
  "https://assets.cognitiveactions.com/invocations/ad7ecfa4-7e54-445b-a4d7-ff38e01e3204/4bb90904-d289-4fe8-a27d-a9428bed6744.webp",
  "https://assets.cognitiveactions.com/invocations/ad7ecfa4-7e54-445b-a4d7-ff38e01e3204/c04ced45-9a8f-4575-8341-d4783ce0b045.webp"
]

Conceptual Usage Example (Python)

Here’s how you can implement the Generate Image Using Inpainting action using Python:

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 = "10197855-a9f9-4fa6-8857-ac69fab4160a" # Action ID for Generate Image Using Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "portrait of dragos",
    "imageFormat": "webp",
    "outputCount": 3,
    "mainLoraScale": 1,
    "enableFastMode": False,
    "inferenceModel": "dev",
    "imageMegapixels": "1",
    "imageAspectRatio": "1:1",
    "imageGuidanceScale": 3,
    "imageOutputQuality": 80,
    "inferenceStepCount": 28,
    "additionalLoraScale": 1,
    "imagePromptStrength": 0.8
}

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, we set the action ID and input payload, then make a POST request to the hypothetical Cognitive Actions execution endpoint. Adjust the input JSON according to the required schema, ensuring the action ID is correctly specified.

Conclusion

The galburdragos/photo-ai Cognitive Actions empower developers to seamlessly integrate advanced image generation capabilities into their applications. By leveraging the Generate Image Using Inpainting action, you can create high-quality, customized images tailored to specific needs. With the provided conceptual examples and guidance, you can easily get started with this powerful functionality. Explore the possibilities of image generation today and enhance your application experiences!