Unlock Creative Possibilities with sinazar/campfire-fox2's Image Generation Action

22 Apr 2025
Unlock Creative Possibilities with sinazar/campfire-fox2's Image Generation Action

In the realm of image synthesis and editing, the sinazar/campfire-fox2 API offers a powerful Cognitive Action that allows developers to generate and customize images seamlessly. Utilizing advanced techniques like img2img and inpainting, this action provides substantial flexibility in generating high-quality visuals tailored to specific prompts. With pre-built features such as LoRA scaling and classifier-free guidance, developers can exert enhanced control over the final output, making it an essential tool for creative applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will be required to authenticate your requests.
  • Basic knowledge of making API calls and handling JSON data in your programming environment of choice.

Authentication typically involves sending the API key in the request headers. This allows you to gain access to the various functionalities offered by the Cognitive Actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create images using either img2img or inpaint modes. You can customize several parameters to influence the output, including image size, refinement style, and prompt influence.

Input

The input schema for this action includes several properties:

  • Mask (URI): A URI pointing to an input mask for inpaint mode. Black areas are preserved, white areas are inpainted.
  • Seed (integer): Seed for random number generation. Leave blank for a randomized seed.
  • Image (URI): A URI of an input image for img2img or inpaint processing.
  • 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"): Text prompt to guide image generation.
  • Refine Style (enum, default: "no_refiner"): Style of refinement to apply (options: no_refiner, expert_ensemble_refiner, base_image_refiner).
  • Lora Scale (number, default: 0.6): Scale for LoRA (Low-Rank Adaptation) additive model.
  • Scheduler Type (enum, default: "K_EULER"): Scheduling algorithm to use (options include DDIM, DPMSolverMultistep, etc.).
  • Num Outputs (integer, default: 1): Number of images to output (ranges between 1 and 4).
  • Refine Steps (integer): Number of refinement steps for base_image_refiner.
  • Custom Weights (string): Optional LoRA weights to use.
  • Guidance Scale (number, default: 7.5): Scale for classifier-free guidance, ranges from 1 to 50.
  • High Noise Frac (number, default: 0.8): Fraction of noise used in expert_ensemble_refiner.
  • Apply Watermark (boolean, default: true): Whether to apply a watermark to generated images.
  • Negative Prompt (string, default: ""): Text prompt to specify what should not be present in the generated image.
  • Prompt Strength (number, default: 0.8): Strength of the prompt when using img2img or inpaint mode.
  • Num Inference Steps (integer, default: 50): Total number of denoising steps to use.
  • Disable Safety Checker (boolean, default: false): Option to disable the safety checker.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A photo of TOK wearing a dark green dress looking at the camera with a big smile, animal crossing, no background",
  "refine": "expert_ensemble_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "numOutputs": 4,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": false,
  "negativePrompt": "realistic",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}

Output

The action typically returns an array of image URLs pointing to the generated images. Here’s an example of the output you can expect:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/e1313512-6460-40e7-be59-16770345bdc1/120aaf09-8ddb-4521-b6e3-b8924fc6a224.png",
  "https://assets.cognitiveactions.com/invocations/e1313512-6460-40e7-be59-16770345bdc1/56f588ec-77bb-4499-8613-4b7d98bfc776.png",
  "https://assets.cognitiveactions.com/invocations/e1313512-6460-40e7-be59-16770345bdc1/eab56fd2-86ca-4cee-ae83-dfa3dffed4c7.png",
  "https://assets.cognitiveactions.com/invocations/e1313512-6460-40e7-be59-16770345bdc1/534d7b03-6ef1-4a73-988a-5754da1615b2.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet that demonstrates how to call the Generate Inpainted 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 = "c9914b69-09d9-49a7-a1b2-ba1c7c0dafd3" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A photo of TOK wearing a dark green dress looking at the camera with a big smile, animal crossing, no background",
    "refine": "expert_ensemble_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "numOutputs": 4,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": False,
    "negativePrompt": "realistic",
    "promptStrength": 0.8,
    "numInferenceSteps": 50
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the input schema, and the action ID is set for the Generate Inpainted Image action. The response is processed to return the URLs of the generated images.

Conclusion

The sinazar/campfire-fox2 Cognitive Action for generating inpainted images offers developers a robust tool for creating customized visuals. With numerous input options and the ability to fine-tune outputs, this action can enhance applications ranging from creative content generation to sophisticated image editing. Start experimenting with the API today to unlock endless creative possibilities!