Elevate Your Image Generation with the vetkastar/fooocus Cognitive Actions

23 Apr 2025
Elevate Your Image Generation with the vetkastar/fooocus Cognitive Actions

In the ever-evolving world of digital art and image generation, the vetkastar/fooocus API stands out by offering a powerful set of Cognitive Actions that simplify the process of creating stunning and customizable images. Among its most compelling features is the ability to generate images with a variety of styles, inpainting capabilities, and advanced controls that enhance detail and quality. This article delves into the key action available in this API, providing developers with everything they need to integrate these transformative capabilities into their own applications.

Prerequisites

Before diving into the implementation, ensure that you have:

  • An API key for accessing the vetkastar/fooocus Cognitive Actions.
  • A basic understanding of JSON and how to make HTTP requests.

Authentication typically involves passing the API key in the request headers, ensuring secure access to the API's functionalities.

Cognitive Actions Overview

Generate and Inpaint Image

The Generate and Inpaint Image action allows developers to create images based on customizable prompts and styles, while also offering inpainting capabilities. This action is particularly useful for enhancing images by filling in missing details or altering specific areas based on user-defined parameters.

Input: The input schema for this action is quite extensive, allowing for various adjustments to the image generation process. Here’s a breakdown of the required and optional fields:

  • prompt (string): The initial text description guiding the image generation (e.g., "woman, illustration, cartoon, soothing tones, calm colors, flowers").
  • imageSeed (integer): A seed value for random generation, defaulting to -1 for randomness.
  • sharpness (number): Controls the clarity of the image (range: 0-30, default is 2).
  • imageNumber (integer): The number of images to generate (1-8, default is 1).
  • guidanceScale (number): Influences the prompts' effect (1-30, default is 7).
  • inpaintingStrength (number): Determines the strength of inpainting (0-1, default is 0.5).
  • styleSelections (string): Comma-separated styles to apply during generation (default is "Fooocus V2,Fooocus Enhance,Fooocus Sharp").
  • aspectRatiosSelection (string): Defines the aspect ratio for the generated image (default is "1152*896").

And many more parameters that allow for fine-tuning the image output.

Example Input:

{
  "prompt": "woman, illustration, cartoon, soothing tones, calm colors, flowers",
  "imageSeed": -1,
  "sharpness": 2,
  "imageNumber": 1,
  "controlType1": "ImagePrompt",
  "guidanceScale": 7,
  "inpaintingStrength": 0.5,
  "styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
  "aspectRatiosSelection": "1024*1024"
}

Output: The output of this action typically returns a JSON object containing the paths to the generated images and the associated seeds used during generation.

Example Output:

{
  "paths": [
    "https://assets.cognitiveactions.com/invocations/96a3ba04-7084-442b-a532-6f6ce15da11d/50d4048f-b8fd-43d7-b647-3be401ef34e9.png"
  ],
  "seeds": [
    283214424716573730
  ]
}

Conceptual Usage Example (Python): Here’s how you might call this action using Python and the requests library. This example illustrates the structure of the input payload:

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 = "09b1544a-8a22-40f2-8366-c768245cb82e"  # Action ID for Generate and Inpaint Image

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "woman, illustration, cartoon, soothing tones, calm colors, flowers",
    "imageSeed": -1,
    "sharpness": 2,
    "imageNumber": 1,
    "guidanceScale": 7,
    "inpaintingStrength": 0.5,
    "styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
    "aspectRatiosSelection": "1024*1024"
}

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 the COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the input schema, allowing for a seamless integration with the API.

Conclusion

The Generate and Inpaint Image action within the vetkastar/fooocus API opens up a plethora of opportunities for developers looking to enhance their applications with advanced image generation capabilities. By leveraging this API, you can create stunning visuals tailored to your specifications, enhance existing images, and ultimately boost user engagement in your projects. Start exploring the potential of these Cognitive Actions today, and transform the way you approach digital art and image generation!