Generate Stunning Images with Cognitive Actions from wiltonn/jamesjockey

In the world of image generation, the Cognitive Actions from the wiltonn/jamesjockey spec offer powerful tools to create visually appealing images based on text prompts. These pre-built actions simplify the integration of complex image generation processes into your applications, allowing developers to harness the capabilities of advanced AI models with minimal effort. Whether for artistic design, marketing, or content creation, these actions can help you enhance your project with custom images tailored to your specifications.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which you will need for authentication.
- Basic knowledge of making API calls and handling JSON data.
Typically, authentication can be achieved by including your API key in the headers of your requests, ensuring secure access to the image generation capabilities.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create images from a text prompt and an optional image mask for inpainting. It supports various configurations, including aspect ratio, dimensions, and output format, while providing two models for different performance needs: 'dev' for detailed generation and 'schnell' for faster results.
Input
The required and optional fields for this action are defined in the following schema:
- prompt (required): Description or command for generating the image.
- image (optional): Input image URI for image-to-image or inpainting mode.
- mask (optional): URI of the image mask for inpainting mode.
- width (optional): Width of the generated image (must be 256-1440).
- height (optional): Height of the generated image (must be 256-1440).
- goFast (optional): Toggle for faster predictions (default: false).
- modelType (optional): Choose between 'dev' or 'schnell' (default: 'dev').
- outputQuantity (optional): Number of image outputs to generate (1-4).
- imageFormat (optional): Defines the format of the output images (default: 'webp').
- guidanceScale (optional): Adjusts the guidance scale for diffusion.
- denoisingSteps (optional): Sets the number of denoising steps (1-50).
Example Input:
{
"image": "https://replicate.delivery/pbxt/LveE11UNhHKs5Uv9u57PeMEyncge5AVPLADUahFDtLlSKaMG/james1.png",
"prompt": "JOK image of James jockey standing beside horse. James is holding his fingers up in the air with Brown substance caked on the ends of his fingers",
"loraScale": 0.73,
"modelType": "dev",
"imageFormat": "jpg",
"guidanceScale": 4.43,
"outputQuality": 96,
"denoisingSteps": 38,
"extraLoraScale": 1,
"outputQuantity": 1,
"promptStrength": 0.9,
"imageAspectRatio": "16:9"
}
Output
The action typically returns a list of generated image URLs. For example:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/6a699b88-2244-4bba-9bd9-b64eb348107a/d6e69d8e-7764-4e6e-aa26-a7d0443abbd7.jpg"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to call the Generate Image with Inpainting 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 = "3c90e12f-4a25-4a4e-8d94-11a8cbcf286c" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/LveE11UNhHKs5Uv9u57PeMEyncge5AVPLADUahFDtLlSKaMG/james1.png",
"prompt": "JOK image of James jockey standing beside horse. James is holding his fingers up in the air with Brown substance caked on the ends of his fingers",
"loraScale": 0.73,
"modelType": "dev",
"imageFormat": "jpg",
"guidanceScale": 4.43,
"outputQuality": 96,
"denoisingSteps": 38,
"extraLoraScale": 1,
"outputQuantity": 1,
"promptStrength": 0.9,
"imageAspectRatio": "16:9"
}
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, the action ID and the input payload are structured according to the requirements discussed. Ensure to replace the endpoint and API key with your actual values.
Conclusion
The Cognitive Actions from wiltonn/jamesjockey empower developers to generate custom images effortlessly using text prompts and various configuration options. By leveraging these actions, you can enhance your applications with unique visual content tailored to your specific needs. Explore the potential of these Cognitive Actions today and elevate your creative projects!