Unlocking Creativity: Integrate Image Generation with sinazar/campfire-deer1 Cognitive Actions

21 Apr 2025
Unlocking Creativity: Integrate Image Generation with sinazar/campfire-deer1 Cognitive Actions

In the realm of digital creativity, the ability to generate and refine images can open up a multitude of possibilities. The sinazar/campfire-deer1 Cognitive Actions API provides developers with powerful tools to create stunning visuals based on user-defined inputs. This API includes a versatile image generation action that allows for image-to-image transformations and inpainting with advanced refinement techniques. By leveraging these pre-built actions, developers can enhance their applications with cutting-edge image generation capabilities without needing to build complex algorithms from scratch.

Prerequisites

To get started with the Cognitive Actions API, you will need:

  • An API key for authentication.
  • Basic knowledge of making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the headers of your request. This allows the service to verify your identity and grant you access to its functionalities.

Cognitive Actions Overview

Generate And Refine Image

The Generate And Refine Image action is designed to create and enhance images using input masks and text prompts. This action supports various modes, including image-to-image translation and inpainting, making it a versatile choice for developers looking to integrate image generation into their applications.

Input

The input for this action requires a JSON object that can include the following fields:

  • mask (string, URI): The URI of the input mask for inpainting. Black areas are preserved; white areas are modified.
  • seed (integer): A random seed value for generating variations. Leave blank for auto-randomization.
  • image (string, URI): The URI of the input image for image-to-image translation or inpainting.
  • width (integer, default: 1024): The width of the output image in pixels.
  • height (integer, default: 1024): The height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): Text prompt to guide image generation.
  • loraScale (number, default: 0.6): Scaling factor for LoRA models, ranging from 0 to 1.
  • scheduler (string, default: "K_EULER"): Method for scheduling denoising steps.
  • refineSteps (integer): Number of steps for refining the base image using a refiner.
  • refineStyle (string, default: "no_refiner"): Select the refinement style to apply.
  • guidanceScale (number, default: 7.5): Strength of classifier-free guidance.
  • applyWatermark (boolean, default: true): Option to add a watermark to the generated image.
  • negativePrompt (string, default: ""): Text prompt that specifies undesired characteristics in the generated image.
  • promptStrength (number, default: 0.8): Strength of the prompt in image-to-image or inpainting modes.
  • numberOfOutputs (integer, default: 1): Specifies the number of images to generate, ranging from 1 to 4.
  • duplicateWeights (string): LoRA weights to use for duplication.
  • highNoiseFraction (number, default: 0.8): Indicates the fraction of noise applied for expert ensemble refiner.
  • disableSafetyChecker (boolean, default: false): Option to disable the safety checker for images.
  • numberOfInferenceSteps (integer, default: 50): Specifies the number of denoising steps.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "a photo of TOK wearing a floral tie and a flower tiara, animal crossing",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "refineStyle": "expert_ensemble_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "negativePrompt": "realistic",
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 75
}

Output

The action will return an array of URIs pointing to the generated images. The output structure may vary, but typically it will look like this:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/ca4bcb19-9dee-4f70-97fd-d7c849b60e0d/0b5aad38-02fa-4467-be63-4d736021fecb.png",
  "https://assets.cognitiveactions.com/invocations/ca4bcb19-9dee-4f70-97fd-d7c849b60e0d/2ed53df9-244a-41e5-8a3e-3aa329a3a96d.png",
  "https://assets.cognitiveactions.com/invocations/ca4bcb19-9dee-4f70-97fd-d7c849b60e0d/cbbe8229-97da-40f4-a871-d3b098623c4b.png",
  "https://assets.cognitiveactions.com/invocations/ca4bcb19-9dee-4f70-97fd-d7c849b60e0d/01658980-a45f-4da3-a024-2f7e7ae87cb3.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to illustrate how you would call the Generate And Refine Image 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 = "f13566df-ad59-4f3a-a357-9ffb809dbbd5" # Action ID for Generate And Refine Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "a photo of TOK wearing a floral tie and a flower tiara, animal crossing",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "refineStyle": "expert_ensemble_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": False,
    "negativePrompt": "realistic",
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "highNoiseFraction": 0.8,
    "numberOfInferenceSteps": 75
}

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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the "Generate And Refine Image" action, and the payload is constructed based on the required input schema. Note that the endpoint URL and request structure are illustrative and may vary.

Conclusion

The sinazar/campfire-deer1 Cognitive Actions API offers developers a robust solution for generating and refining images with ease. By integrating these actions into your applications, you can provide users with innovative features that enhance their creative experience. Whether for art generation, content creation, or other applications, the possibilities are vast. Consider exploring further use cases or combining this action with others to unlock even more potential!