Generate Stunning Images with the vetkastar/fooocus Cognitive Actions

The vetkastar/fooocus API offers powerful Cognitive Actions designed for image generation and enhancement. Among its features, the most notable is the ability to generate custom images with inpainting capabilities, allowing developers to create unique visual content tailored to specific needs. By leveraging these pre-built actions, developers can save time and resources while enhancing their applications with advanced image manipulation tools.
Prerequisites
To integrate the Cognitive Actions provided by the vetkastar/fooocus API, you'll need to have:
- An API key to access the Cognitive Actions platform.
- A basic understanding of how to make HTTP requests to an API.
Authentication typically involves including the API key in the request headers to authorize access to the actions.
Cognitive Actions Overview
Generate Custom Images with Inpainting
Purpose:
This action generates images using the Fooocus API, with capabilities for inpainting, custom LoRA URLs, and various style adjustments. It allows for detailed customization of the generated images, making it ideal for developers looking to create visually appealing content.
Category: Image Generation
Input
The input for this action requires a JSON object that contains several properties. Below are the key fields:
- prompt (string): A description of the image to be generated.
Example:"woman, illustration, cartoon, soothing tones, calm colors, flowers" - imageSeed (integer): Seed to generate image; use
-1for random.
Example:-1 - sharpness (number): Controls the sharpness of the generated image.
Example:2(range:0to30) - imageNumber (integer): Number of images to generate (between
1and8).
Example:1 - guidanceScale (number): Scale of guidance applied during image generation.
Example:7(range:1to30) - styleSelections (string): Styles applied for image generation, separated by commas.
Example:"Fooocus V2,Fooocus Enhance,Fooocus Sharp" - inpaintStrength (number): Denoising strength for inpainting (between
0and1).
Example:0.5
Here’s a complete example input JSON:
{
"prompt": "woman, illustration, cartoon, soothing tones, calm colors, flowers",
"imageSeed": -1,
"sharpness": 2,
"imageNumber": 1,
"guidanceScale": 7,
"styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
"inpaintStrength": 0.5,
"useDefaultLoras": true,
"outpaintSelections": "",
"outpaintDistanceTop": 0,
"upscaleOrVaryMethod": "Disabled",
"outpaintDistanceLeft": 0,
"performanceSelection": "Speed",
"aspectRatiosSelection": "1024*1024",
"outpaintDistanceRight": 0,
"outpaintDistanceBottom": 0,
"inpaintAdditionalPrompt": ""
}
Output
The output typically returns a list of image paths along with the seeds used for generation:
{
"paths": [
"https://assets.cognitiveactions.com/invocations/1b8943b2-202e-47a7-aa5a-73cdd443a178/356fa6dd-84ec-4156-8032-262a74f59cbc.png"
],
"seeds": [
7972505196212722000
]
}
Conceptual Usage Example (Python)
Here’s how you might call the Generate Custom Images with Inpainting action using Python:
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 = "ddd3c89e-2feb-466d-8267-90bb4074b1d6" # Action ID for Generate Custom 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,
"styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
"inpaintStrength": 0.5,
"useDefaultLoras": true,
"outpaintSelections": "",
"outpaintDistanceTop": 0,
"upscaleOrVaryMethod": "Disabled",
"outpaintDistanceLeft": 0,
"performanceSelection": "Speed",
"aspectRatiosSelection": "1024*1024",
"outpaintDistanceRight": 0,
"outpaintDistanceBottom": 0,
"inpaintAdditionalPrompt": ""
}
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}
)
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 will need to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Custom Images with Inpainting action. The payload is constructed using the required input fields, and an HTTP POST request is sent to the hypothetical endpoint.
Conclusion
The vetkastar/fooocus API offers a robust solution for developers seeking to enhance their applications with advanced image generation capabilities. With features like inpainting and customizable styling, you can create stunning visuals tailored to your specifications. Explore how these Cognitive Actions can elevate your projects and consider integrating them into your workflows for a seamless development experience.