Enhance Your Apps with Image Generation Using the victormustin/test-finetune-general-1 Actions

24 Apr 2025
Enhance Your Apps with Image Generation Using the victormustin/test-finetune-general-1 Actions

In the realm of artificial intelligence, image generation has become a powerful tool for developers looking to enrich their applications. The victormustin/test-finetune-general-1 API offers a sophisticated Cognitive Action for generating images through inpainting techniques. This action allows you to customize various parameters, ensuring your generated images meet your specific needs. By leveraging pre-built actions, you can save time and focus on building engaging features for your users.

Prerequisites

Before diving into using the Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with JSON for structuring your requests.
  • Understanding of how to make HTTP requests to a given endpoint.

Authentication usually involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using inpainting techniques while providing flexibility through customizable parameters. This action can produce variations based on random seeds and supports several options for image size and output count.

Input

The input schema for this action requires several parameters, as detailed below:

  • mask (string, required): URI of the input mask for inpaint mode. Black areas will be preserved, while white areas will be inpainted.
  • seed (integer, optional): Random seed for generating consistent output. Leave blank for a random seed.
  • image (string, required): URI of the input image for img2img or inpaint mode.
  • width (integer, default: 1024): Width of the output image in pixels.
  • height (integer, default: 1024): Height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): Descriptive input prompt guiding image generation.
  • loraWeights (string, optional): Specify the LoRA weights for image generation.
  • refineStyle (string, default: "no_refiner"): Options include "no_refiner", "expert_ensemble_refiner", and "base_image_refiner".
  • scheduleType (string, default: "K_EULER"): Select the scheduler type for the process.
  • negativePrompt (string, optional): Terms and styles to avoid in the image generation.
  • enableWatermark (boolean, default: true): Enable or disable watermark application.
  • numberOfOutputs (integer, default: 1): Specify the number of images to generate (1-4).
  • safetyCheckerOff (boolean, default: false): Toggle to disable the safety checker for generated images.
  • guidanceIntensity (number, default: 7.5): Intensity scale for classifier-free guidance.
  • highNoiseFraction (number, default: 0.8): Fraction of noise to apply when using "expert_ensemble_refiner".
  • loraAdditiveScale (number, default: 0.6): Additive scale for LoRA, applicable to trained models.
  • inferenceStepsCount (integer, default: 50): Number of denoising steps for inference.
  • inputPromptStrength (number, default: 0.8): Strength of the prompt's influence.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "in the style of TOK, a dining table, pierre cardin, inviting, relaxed, retro, mid-century, rich wood",
  "refineStyle": "no_refiner",
  "scheduleType": "K_EULER",
  "negativePrompt": "bad quality, illustration, 2d, cartoons",
  "enableWatermark": false,
  "numberOfOutputs": 4,
  "guidanceIntensity": 7.5,
  "highNoiseFraction": 0.8,
  "loraAdditiveScale": 0.6,
  "inferenceStepsCount": 50,
  "inputPromptStrength": 0.8
}

Output

The action typically returns an array of URIs pointing to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/f1744a19-435a-420e-90cc-c941fb07c049/8c3bd7d2-b65e-48ac-95c8-7e7f0d41d531.png",
  "https://assets.cognitiveactions.com/invocations/f1744a19-435a-420e-90cc-c941fb07c049/e7ce4d12-e248-4785-af9e-d848a0ef6da2.png",
  "https://assets.cognitiveactions.com/invocations/f1744a19-435a-420e-90cc-c941fb07c049/861971c7-3ae5-4216-a1fb-bae3d28c9714.png",
  "https://assets.cognitiveactions.com/invocations/f1744a19-435a-420e-90cc-c941fb07c049/ef581c0f-458f-42a3-ae0e-ca09a31de36f.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to invoke 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 = "30c227fb-7878-4c0b-b425-6c8d5efb9f7f"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "in the style of TOK, a dining table, pierre cardin, inviting, relaxed, retro, mid-century, rich wood",
    "refineStyle": "no_refiner",
    "scheduleType": "K_EULER",
    "negativePrompt": "bad quality, illustration, 2d, cartoons",
    "enableWatermark": False,
    "numberOfOutputs": 4,
    "guidanceIntensity": 7.5,
    "highNoiseFraction": 0.8,
    "loraAdditiveScale": 0.6,
    "inferenceStepsCount": 50,
    "inputPromptStrength": 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, you'll need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID corresponds to the Generate Image with Inpainting action. The payload is constructed using the example input, and the response will contain the generated image URIs.

Conclusion

The Generate Image with Inpainting action from the victormustin/test-finetune-general-1 API offers a robust solution for developers looking to integrate image generation capabilities into their applications. With its range of customizable parameters, you can create unique and tailored images that enhance user engagement. Start exploring the possibilities today and see how image generation can transform your projects!