Mastering Image Generation and Enhancement with vetkastar/fooocus Cognitive Actions

22 Apr 2025
Mastering Image Generation and Enhancement with vetkastar/fooocus Cognitive Actions

In the world of digital content creation, having the ability to generate and refine images is invaluable. The vetkastar/fooocus API provides developers with a powerful toolset through its Cognitive Actions, particularly focusing on advanced image generation techniques. This set of actions allows for high-quality image production with customizable parameters, enhancing both creativity and accuracy. By integrating these pre-built actions into your applications, you can automate and elevate your image creation workflows.

Prerequisites

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

  • An API key for accessing the vetkastar/fooocus Cognitive Actions platform.
  • A basic understanding of JSON structure and API requests.

For authentication, you'll typically pass your API key in the headers of your requests. Here’s a conceptual example of how to set up your request:

headers = {
    "Authorization": f"Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

Cognitive Actions Overview

Generate and Enhance Images with Inpainting

Description: This action facilitates the generation of high-quality images using a robust inpainting process. It integrates customizable parameters such as inpainting strength, sharpness, and various control options, allowing for enhanced accuracy and style in the resulting images.

Category: image-generation

Input

The input for this action is structured as a JSON object. Here’s an overview of the required and optional fields based on the schema:

  • prompt (string): A descriptive text basis for the image, e.g., "woman, illustration, cartoon, soothing tones, calm colors, flowers".
  • imageSeed (integer): Seed value for randomization, set to -1 for random values.
  • sharpness (number): Sharpness level of the image (range: 0 to 30).
  • imageNumber (integer): Number of images to generate (1 to 8).
  • guidanceScale (number): Overall influence of guidance (1 to 30).
  • inpaintStrength (number): Strength of the inpainting effect (0 to 1).
  • styleSelections (string): Comma-separated list of styles, e.g., "Fooocus V2,Fooocus Enhance,Fooocus Sharp".
  • aspectRatioOption (string): Width-to-height ratio of the generated image, e.g., "1024*1024".

Here’s an example of the full input JSON payload:

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

Output

The output from this action typically includes the following:

  • paths (array): An array containing URLs to the generated images.
  • seeds (array): An array of the seed values used for image generation.

Here is an example of the expected output:

{
  "paths": [
    "https://assets.cognitiveactions.com/invocations/93d6e0e5-c2b7-4874-b227-230ec79a26f7/0ecec009-ef64-4795-8dfe-9a1f941e0828.png"
  ],
  "seeds": [
    4136463138081759700
  ]
}

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to call the image generation action using the Cognitive Actions API:

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 = "b327c65b-a73a-4221-b585-fd30d8b04989"  # Action ID for Generate and Enhance Images with Inpainting

# 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,
    "inpaintStrength": 0.5,
    "styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
    "aspectRatioOption": "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 snippet, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The payload is constructed based on the input schema, and the action is invoked by making a POST request to the Cognitive Actions API.

Conclusion

The vetkastar/fooocus Cognitive Actions provide a robust framework for developers looking to integrate advanced image generation and enhancement capabilities into their applications. By leveraging the Generate and Enhance Images with Inpainting action, you can create visually stunning content with ease. Consider exploring additional use cases where these actions can streamline your workflows and enhance user experiences. Happy coding!