Create Stunning Images with the vetkastar/fooocus Cognitive Actions

In today's digital landscape, generating captivating images is more important than ever. The vetkastar/fooocus API provides a powerful set of Cognitive Actions that allow developers to create custom inpainted images with advanced features like adjustable inpaint strength, custom LoRAs URLs, and performance modes for optimized speed and quality. By leveraging these pre-built actions, developers can enhance their applications with sophisticated image generation capabilities without starting from scratch.
Prerequisites
To get started with the Cognitive Actions provided by the vetkastar/fooocus API, you will need:
- An API key for authentication, which should be included in the headers of your HTTP requests.
- Basic familiarity with RESTful APIs and JSON payloads.
Conceptually, authentication can be accomplished by passing your API key in the request headers, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Custom Inpainted Images
Description: This action enables the generation of images using custom inpainting techniques. It offers features like adjustable inpaint strength and custom LoRAs URLs, along with enhancements for performance modes to balance speed and quality.
Category: image-generation
Input
The input schema for this action is quite comprehensive, allowing for various configurations. Here are the key fields:
- type1 (string): Control Net Type 1 (e.g., "ImagePrompt", "FaceSwap"). Defaults to "ImagePrompt".
- prompt (string): A descriptive text prompt to guide the image generation process.
- imageSeed (integer): A seed for generating the image; -1 for a random seed.
- sharpness (number): The sharpness of the generated image, defaulting to 2.
- imageNumber (integer): The number of images to generate, with a default of 1.
- guidanceScale (number): The scale of guidance during the generation, defaulting to 7.
- inpaintStrength (number): The strength for inpainting, ranging from 0 to 1, defaulting to 0.5.
Example Input:
{
"type1": "ImagePrompt",
"type2": "ImagePrompt",
"type3": "ImagePrompt",
"type4": "ImagePrompt",
"prompt": "woman, illustration, cartoon, soothing tones, calm colors, flowers",
"imageSeed": -1,
"sharpness": 2,
"imageNumber": 1,
"upscaleValue": 0,
"guidanceScale": 7,
"refinerSwitch": 0.5,
"negativePrompt": "",
"customLorasUrls": "",
"inpaintStrength": 0.5,
"styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
"useDefaultLoras": true,
"variationMethod": "Disabled",
"outpaintSelections": "",
"outpaintDistanceTop": 0,
"outpaintDistanceLeft": 0,
"performanceSelection": "Speed",
"aspectRatiosSelection": "1024*1024",
"outpaintDistanceRight": 0,
"outpaintDistanceBottom": 0,
"inpaintAdditionalPrompt": ""
}
Output
The action typically returns a JSON object containing the paths to the generated images and the seeds used for generation.
Example Output:
{
"paths": [
"https://assets.cognitiveactions.com/invocations/7ec04836-7ca9-42e6-8a22-38741c8433cf/c301291b-4020-4703-8774-5e62a4dbee9a.png"
],
"seeds": [
2560431320736569300
]
}
Conceptual Usage Example (Python)
Here’s how you might structure a call to the Generate Custom Inpainted Images 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 = "09bfe411-2d69-422a-a686-9bc08121c412" # Action ID for Generate Custom Inpainted Images
# Construct the input payload based on the action's requirements
payload = {
"type1": "ImagePrompt",
"type2": "ImagePrompt",
"type3": "ImagePrompt",
"type4": "ImagePrompt",
"prompt": "woman, illustration, cartoon, soothing tones, calm colors, flowers",
"imageSeed": -1,
"sharpness": 2,
"imageNumber": 1,
"upscaleValue": 0,
"guidanceScale": 7,
"refinerSwitch": 0.5,
"negativePrompt": "",
"customLorasUrls": "",
"inpaintStrength": 0.5,
"styleSelections": "Fooocus V2,Fooocus Enhance,Fooocus Sharp",
"useDefaultLoras": True,
"variationMethod": "Disabled",
"outpaintSelections": "",
"outpaintDistanceTop": 0,
"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} # 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 Python snippet, replace the "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action ID is set to the specific action you want to execute. The input payload is constructed based on the requirements outlined above, and the response is parsed to retrieve the generated image paths.
Conclusion
The vetkastar/fooocus Cognitive Actions offer a robust solution for developers looking to integrate advanced image generation capabilities into their applications. With the ability to customize inpainting techniques and control various generation parameters, these actions can significantly enhance user experiences.
Next steps could include experimenting with different input configurations to discover creative possibilities or integrating the action into a larger image processing workflow. Dive in and start creating stunning images today!