Generate Stunning Images with the Coder-Pranav Image Better Text Action

In today's digital landscape, creating high-quality images based on textual descriptions has become an essential tool for developers and designers alike. The Coder-Pranav Image Better Text API introduces a powerful Cognitive Action that allows you to generate custom images tailored to your specific needs. With its intuitive parameters for size, quality, format, and guidance scale, you can achieve accurate and high-quality outputs effortlessly.
Prerequisites
Before you dive into using the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic familiarity with making HTTP requests and handling JSON data.
Authentication generally involves passing your API key in the request headers to authorize your access to the service.
Cognitive Actions Overview
Generate Custom Image
Description:
The Generate Custom Image action allows users to create images based on a provided textual prompt. This action supports various customizable parameters, including image dimensions, quality, format, and more, ensuring you can fine-tune the output to meet your requirements.
Category:
Image Generation
Input
The input schema for this action is a JSON object containing the following fields:
- seed (optional): An integer to ensure reproducibility of results. If not specified, a random seed is used.
- steps (optional): The number of inference steps (default: 28, range: 1-50).
- width (optional): The width of the image in pixels (default: 1024, range: 512-2048).
- height (optional): The height of the image in pixels (default: 1024, range: 512-2048).
- prompt (required): A string containing the text prompt for the image generation.
- imageCount (optional): The number of images to generate (default: 1, range: 1-10).
- outputFormat (optional): The file format of the output images (default: webp; options: webp, jpg, png).
- guidanceScale (optional): A number that adjusts how closely the image should adhere to the prompt (default: 3.5, range: 0-20).
- outputQuality (optional): An integer indicating the quality of the output images (default: 95, range: 0-100).
Example Input:
{
"steps": 42,
"width": 1024,
"height": 1024,
"prompt": "a photo of heaven with title saying welcome to hell with an emoji",
"imageCount": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 95
}
Output
The output of this action typically returns a URL pointing to the generated image. For example:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/c6f40282-a93b-47e8-b4ba-63eefbd619b9/2c3f74d5-f0a9-4d94-a832-ea65c2cfe1b4.png"
]
Conceptual Usage Example (Python)
Here’s how you could use the Generate Custom Image action in a Python application:
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 = "d804b317-67a8-46bd-815f-74c83330f4d0" # Action ID for Generate Custom Image
# Construct the input payload based on the action's requirements
payload = {
"steps": 42,
"width": 1024,
"height": 1024,
"prompt": "a photo of heaven with title saying welcome to hell with an emoji",
"imageCount": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 95
}
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, we make a POST request to the hypothetical endpoint for executing the Generate Custom Image action. We structure the input payload according to the schema and handle any potential errors gracefully.
Conclusion
The Coder-Pranav Image Better Text Cognitive Actions provide an impressive way to generate custom images from textual prompts, offering flexibility and quality to developers. By leveraging these actions, you can enhance your applications with rich visual content tailored to your specifications. Explore different use cases, adjust the parameters, and see the creative possibilities unfold!