Generate Stunning Images with basta/tomas.flux Cognitive Actions

In the world of digital content creation, the ability to generate high-quality images programmatically can significantly enhance applications, from gaming to marketing. The basta/tomas.flux specification offers a powerful Cognitive Action that enables developers to create images with customizable attributes such as resolution, aspect ratio, and style. By leveraging these pre-built actions, developers can save time and resources while delivering impressive visual content tailored to their specific needs.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- API Key: You will need an API key to authenticate requests to the Cognitive Actions platform. This key should be included in the request headers.
- Environment Setup: Ensure your development environment is ready to make HTTP requests. You can use libraries like
requestsin Python for this purpose.
Authentication typically involves passing the API key in the headers of your HTTP requests, allowing you to securely invoke the Cognitive Actions.
Cognitive Actions Overview
Generate Image with Custom Settings
The "Generate Image with Custom Settings" action allows you to create high-quality images based on customizable parameters, including resolution, aspect ratio, and style strengths. You can choose between detailed results with the 'Dev' model or faster generation with the 'Schnell' model. This action supports advanced features such as image inpainting and image-to-image transformations.
Input
The required input for this action is structured as follows:
{
"prompt": "A detailed description of the image you want to generate.",
"loraScale": 1,
"modelType": "dev",
"numOutputs": 1,
"guidanceScale": 3.5,
"extraLoraScale": 1,
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 90
}
Example Input:
{
"prompt": "\"A portrait of TSTUD, a fit man with glasses and long hair tied in a neat braid and a well-groomed beard, standing confidently on a sunny beach. He's wearing stylish swim trunks that complement his athletic physique. His posture is relaxed yet poised, showcasing his toned muscles without being overly provocative. The lighting is warm and natural, highlighting his sun-kissed skin and the texture of his hair and beard. In the background, you can see the ocean and perhaps some beach activities. The overall atmosphere is one of health, vitality, and summer enjoyment. The image is captured with a high-quality camera, emphasizing clarity and natural colors. The composition should be tasteful and focused on TSTUD's face and upper body, maintaining a respectful and non-objectifying portrayal.\"",
"loraScale": 1,
"modelType": "dev",
"numOutputs": 1,
"guidanceScale": 3.5,
"extraLoraScale": 1,
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 90
}
Output
The action returns a list of generated image URLs. The output typically resembles the following structure:
[
"https://assets.cognitiveactions.com/invocations/efb2c737-f2a6-4cb8-846a-3ab08b11c721/95d8fe71-9636-4ec3-a122-c4d2ad50d6c9.webp"
]
Conceptual Usage Example (Python)
Here’s how you might invoke this 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 = "8e247e86-e862-4cb0-8dc7-4ff385fa07f2" # Action ID for Generate Image with Custom Settings
# Construct the input payload based on the action's requirements
payload = {
"prompt": "\"A portrait of TSTUD, a fit man with glasses and long hair tied in a neat braid and a well-groomed beard, standing confidently on a sunny beach. He's wearing stylish swim trunks that complement his athletic physique. His posture is relaxed yet poised, showcasing his toned muscles without being overly provocative. The lighting is warm and natural, highlighting his sun-kissed skin and the texture of his hair and beard. In the background, you can see the ocean and perhaps some beach activities. The overall atmosphere is one of health, vitality, and summer enjoyment. The image is captured with a high-quality camera, emphasizing clarity and natural colors. The composition should be tasteful and focused on TSTUD's face and upper body, maintaining a respectful and non-objectifying portrayal.\"",
"loraScale": 1,
"modelType": "dev",
"numOutputs": 1,
"guidanceScale": 3.5,
"extraLoraScale": 1,
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 90
}
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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is built based on the required schema, and the action is invoked via a POST request to the hypothetical endpoint. The response is then handled, displaying either the generated image URLs or any error messages.
Conclusion
The Generate Image with Custom Settings action from the basta/tomas.flux specification empowers developers to harness advanced image generation capabilities seamlessly. By integrating this action, you can create stunning visuals tailored to your application's needs, whether for marketing, storytelling, or creative projects. Explore further possibilities by experimenting with different parameters and settings to achieve the best results for your projects!