Create Stunning Images Effortlessly with Imagegen

The Imagegen service offers powerful Cognitive Actions designed to streamline the image generation process, allowing developers to create high-quality, customizable images seamlessly. With advanced features such as inpainting, prompt strength adjustment, and support for various models, Imagegen provides a robust solution for all your image synthesis needs. Whether you’re enhancing existing images or generating new ones from scratch, Imagegen simplifies the workflow, saving you time and resources while ensuring high-quality outputs.
Common use cases for Imagegen include creating marketing visuals, enhancing product images, generating unique artwork, and even modifying existing images for specific purposes. By leveraging the capabilities of Imagegen, developers can easily integrate sophisticated image generation features into their applications, enhancing user experience and engagement.
Before diving into the integration, ensure you have a valid Cognitive Actions API key and a basic understanding of making API calls.
Generate Enhanced Image
The "Generate Enhanced Image" action is the cornerstone of Imagegen, designed to create high-quality images through advanced synthesis and inpainting techniques. This action solves the problem of needing high-quality visuals that can be tailored to specific requirements, whether for marketing, social media, or personal projects.
Input Requirements
To utilize this action, you must provide a structured input that includes:
- Prompt: A text description guiding the image generation.
- Image (optional): A URI for an input image when using image-to-image transformations.
- Mask (optional): A URI for masking areas of the image for inpainting.
- Additional parameters such as dimensions, quality, and model selection can further customize the output.
Example input:
{
"image": "https://replicate.delivery/pbxt/MT9JQ32w3hUP2NwomtzKGtqpyUtHRVssHshVJLVPg3VolVzY/447481818_1816856972169804_159987833036770899_n.jpg",
"goFast": false,
"prompt": "Replace this man with a photo of EAMONAI, posing for a photo, wearing a fitted shirt, looking well groomed, with a silver chain IMG_137.HEIC",
"loraScale": 1,
"outputCount": 4,
"imageQuality": 80,
"guidanceScale": 3,
"inferenceModel": "dev",
"inferenceSteps": 28,
"promptStrength": 0.8,
"imageResolution": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "png",
"additionalLoraScale": 1
}
Expected Output
The action will produce a set of high-quality images based on the provided prompt and parameters. The output will be a list of URIs pointing to the generated images, allowing for easy access and integration into your applications.
Example output:
[
"https://assets.cognitiveactions.com/invocations/f6463765-da47-4a09-821c-f8b062601e4c/351d9812-4429-4c24-b016-669b69dd0bf6.png",
"https://assets.cognitiveactions.com/invocations/f6463765-da47-4a09-821c-f8b062601e4c/c2d99448-466c-49e2-83c1-8df92d428eff.png",
"https://assets.cognitiveactions.com/invocations/f6463765-da47-4a09-821c-f8b062601e4c/40befdea-4122-40ee-8615-865f7c551bda.png",
"https://assets.cognitiveactions.com/invocations/f6463765-da47-4a09-821c-f8b062601e4c/bec42596-dff7-4f7d-b5c2-5c50728f079b.png"
]
Use Cases for this Action
- Marketing and Advertising: Generate eye-catching visuals tailored to specific campaigns or products.
- Social Media Content Creation: Quickly create unique images to enhance engagement with followers.
- Artistic Projects: Artists can use this action to explore new styles or concepts by synthesizing images based on prompts.
- E-commerce: Enhance product images by modifying them to better fit the brand aesthetic or to highlight features.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "bf304d57-7b60-411d-a895-e3245db2d166" # Action ID for: Generate Enhanced Image
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"image": "https://replicate.delivery/pbxt/MT9JQ32w3hUP2NwomtzKGtqpyUtHRVssHshVJLVPg3VolVzY/447481818_1816856972169804_159987833036770899_n.jpg",
"goFast": false,
"prompt": "Replace this man with a photo of EAMONAI, posing for a photo, wearing a fitted shirt, looking well groomed, with a silver chain IMG_137.HEIC",
"loraScale": 1,
"outputCount": 4,
"imageQuality": 80,
"guidanceScale": 3,
"inferenceModel": "dev",
"inferenceSteps": 28,
"promptStrength": 0.8,
"imageResolution": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "png",
"additionalLoraScale": 1
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
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 (non-JSON): {e.response.text}")
print("------------------------------------------------")
Conclusion
Imagegen empowers developers to create stunning, high-quality images with ease, opening up a world of possibilities for various applications. By harnessing the capabilities of the "Generate Enhanced Image" action, you can significantly enhance your projects, whether for marketing, social media, or creative endeavors. As you explore Imagegen further, consider experimenting with different parameters and prompts to unlock the full potential of image generation in your applications. Start integrating Imagegen today and elevate your visual content creation to new heights!