Unleashing Creativity: Integrate Image Generation with the BioShock Cognitive Actions

In the ever-evolving landscape of artificial intelligence, the ability to generate and manipulate images through Cognitive Actions stands out as a transformative capability. The BioShock Cognitive Actions provide developers with powerful tools for creating inpainted images, allowing for artistic and practical applications alike. By utilizing these pre-built actions, developers can enhance their applications with advanced image generation features with ease.
Prerequisites
Before diving into the integration of the BioShock Cognitive Actions, ensure that you have the following:
- An API key for the Cognitive Actions platform, which will be essential for authentication.
- Basic familiarity with JSON structures and HTTP requests, as these will be used to interact with the API.
Authentication typically involves passing your API key in the request headers, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Inpainted Image
Description: The Generate Inpainted Image action allows you to create an image by applying a mask that specifies areas for modification, combined with a text prompt that guides the image's creation. This action is particularly useful for customizing images with various settings, providing flexibility in the image generation process.
Category: Image Generation
Input
The input for this action requires a structured JSON object. Below is the schema detailing the required and optional fields:
{
"mask": "https://example.com/mask.png", // URI of the input mask
"seed": 42, // Optional random seed
"image": "https://example.com/input-image.png", // URI of the input image
"width": 1024, // Output image width
"height": 1024, // Output image height
"prompt": "A futuristic cityscape", // Text prompt
"outputCount": 4, // Number of images to generate
"refineStyle": "no_refiner", // Refinement style
"scheduleMode": "K_EULER", // Scheduling algorithm
"loraIntensity": 0.6, // LoRA intensity
"noiseFraction": 0.8, // Noise fraction for refinement
"inferenceSteps": 50, // Total denoising steps
"enableWatermark": true, // Watermark application
"promptIntensity": 0.8, // Prompt intensity
"disallowedPrompt": "", // Optional negative input prompt
"guidanceIntensity": 7.5 // Guidance intensity
}
Example Input:
{
"width": 1024,
"height": 1024,
"prompt": "digital art in the style of JSP",
"outputCount": 4,
"refineStyle": "no_refiner",
"scheduleMode": "K_EULER",
"loraIntensity": 0.6,
"noiseFraction": 0.8,
"inferenceSteps": 50,
"enableWatermark": true,
"promptIntensity": 0.8,
"disallowedPrompt": "",
"guidanceIntensity": 7.5
}
Output
When the action is executed successfully, it returns an array of URIs pointing to the generated images. Here’s an example of the output you can expect:
[
"https://assets.cognitiveactions.com/invocations/356abc8f-6ed8-40e4-b7e7-2f943f495077/c4c1725a-e69a-42c2-9342-730fd4ab2614.png",
"https://assets.cognitiveactions.com/invocations/356abc8f-6ed8-40e4-b7e7-2f943f495077/36bf934b-19ee-444a-ad7e-ab9fcd251f34.png",
"https://assets.cognitiveactions.com/invocations/356abc8f-6ed8-40e4-b7e7-2f943f495077/a98f596d-178a-4b18-9a8d-57f4287b1a84.png",
"https://assets.cognitiveactions.com/invocations/356abc8f-6ed8-40e4-b7e7-2f943f495077/8ad96dd5-7e5d-4947-90e3-9c5c0678c409.png"
]
Conceptual Usage Example (Python)
Below is a conceptual example of how you might call the Generate Inpainted Image action using Python. This code demonstrates how to structure your input JSON payload and handle the API request.
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 = "077a3d7b-8b74-41e9-af31-95dc8573fcdc" # Action ID for Generate Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "digital art in the style of JSP",
"outputCount": 4,
"refineStyle": "no_refiner",
"scheduleMode": "K_EULER",
"loraIntensity": 0.6,
"noiseFraction": 0.8,
"inferenceSteps": 50,
"enableWatermark": true,
"promptIntensity": 0.8,
"disallowedPrompt": "",
"guidanceIntensity": 7.5
}
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 example, replace the placeholder for the API key and ensure that the endpoint and action ID are accurate. The input payload is structured according to the action's schema, allowing for seamless integration into your application.
Conclusion
The BioShock Cognitive Actions empower developers to leverage advanced image generation capabilities effortlessly. By integrating the Generate Inpainted Image action, you can create customized images that meet various artistic and practical needs. Explore these actions further to unlock new creative possibilities for your applications!