Create Stunning Images from Text Prompts with Cognitive Actions

In the ever-evolving landscape of digital content creation, the ability to generate images from text prompts opens up a world of possibilities for developers and creators alike. The "C" service provides powerful Cognitive Actions to transform descriptive text into visually captivating images. This not only speeds up the creative process but also simplifies the workflow for projects that require unique visuals tailored to specific narratives or themes.
Whether you're developing an application that needs custom illustrations, enhancing marketing materials with tailored graphics, or creating engaging social media content that stands out, this image generation capability can significantly enhance your offerings. Imagine being able to generate artwork based on detailed descriptions or even modifying existing images through inpainting—all at your fingertips.
Prerequisites
To get started with the Cognitive Actions, you'll need an API key for the service and a basic understanding of how to make API calls.
Generate Image From Text Prompt
This action allows you to create images based on a descriptive text prompt using a specified inference model. It supports advanced features such as image inpainting with custom masks, aspect ratio adjustments, and various output quality settings. By utilizing models like 'dev' for optimal quality and 'schnell' for rapid generation, this action caters to diverse needs.
Purpose
The "Generate Image From Text Prompt" action addresses the challenge of creating high-quality visuals from textual descriptions, making it easier for developers to integrate unique imagery into their applications.
Input Requirements
To use this action, you must provide a JSON object with the following key parameters:
- prompt (required): The descriptive text used to generate the image.
- Optional parameters include:
- mask: A URI for an image mask for inpainting.
- image: A URI for an input image for transformation.
- width and height: Dimensions for custom aspect ratios.
- denoisingSteps: Number of steps for image refinement.
- inferenceModel: Choose between 'dev' or 'schnell'.
- outputImageCount: Specify how many images to generate.
Expected Output
The output will be a list of image URLs, each corresponding to the generated images based on the provided prompt and parameters.
Use Cases for this specific action
- Marketing Material Creation: Rapidly generate custom images for advertising campaigns based on specific themes or concepts.
- Content Generation: Create unique illustrations for blogs or articles that visually represent the content.
- Game Development: Produce character designs or environment art directly from descriptive narratives, enhancing the visual storytelling aspect of games.
```python
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 = "e2bdf2b5-25ec-487e-806a-3abf12c79a3c" # Action ID for: Generate Image From Text Prompt
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"prompt": "TOK He’s the kind of man who doesn’t just enter a room—he owns it. His presence is magnetic, drawing the eyes of everyone around him, and it's not just the sharp cut of his jawline or the confident stance that makes him irresistible. It’s the aura of power and allure that surrounds him. His face is impossibly handsome, with strong, angular features—high cheekbones, a jawline that could cut glass, and eyes so deep and intense that they seem to peer straight into your soul. His lips, full and slightly parted, hold a smile that’s both devil-may-care and impossibly charming, as if he knows exactly the effect he has on the world around him.\n\nDressed to perfection, his outfit is the embodiment of modern luxury. The tailored suit he wears fits his frame as if it were made just for him—fitted perfectly around his broad shoulders and chest, tapering to highlight his narrow waist and muscular legs. The fabric is sleek and impeccable, glistening subtly under the lights, a deep navy blue that brings out the intensity of his eyes. His shirt, unbuttoned just enough to reveal the faint outline of his toned chest, adds a touch of casual sensuality to an otherwise flawless ensemble. A leather belt cinches his waist, polished shoes gleaming with precision, and a watch—sleek and understated—peeks out from under his cuff, signaling success without shouting it.\n\nThere’s something undeniably sexy about the way he wears his luxury, as if it’s a natural extension of who he is. Every detail, from the fine tailoring to the crisp lines of his clothes, speaks to a man who knows exactly how to present himself. He is the very definition of elegance, but with an edge—like a lion in a perfectly tailored suit, calm but always ready to strike.\n\nAround him, beautiful women can't help but admire him, their eyes lingering on him with a mix of awe and desire. He doesn’t need to chase attention; it comes to him effortlessly, as if drawn to the energy he exudes. There’s a sense of wildness in the way he moves, an underlying danger and passion that only adds to his charm. Yet, when he looks at you, his gaze softens. In that moment, there’s tenderness—an unspoken connection that makes you feel like you’re the only one who matters in the room.\n\nHis laughter, deep and rich, fills the air like a private invitation, and when he speaks, every word feels like it’s been carefully crafted to stir something deep inside you. It's as if he knows the power of his own charm, and he wields it with the precision of a master—always making you feel like the most important person in the room, without ever having to try too hard.\n\nIn this space filled with admiration and envy, he stands tall, the perfect mix of a savage spirit and refined luxury. A man who can command attention with just a glance, a smile, or the slight lean of his body as he walks past, sending shivers of desire rippling through the crowd. He’s not just handsome—he’s untouchably alluring, a man who embodies success, sensuality, and wild charisma in every fiber of his being.",
"denoisingSteps": 28,
"inferenceModel": "dev",
"imageAspectRatio": "1:1",
"outputImageCount": 4,
"imageOutputFormat": "jpg",
"mainLoraIntensity": 1,
"imageOutputQuality": 90,
"img2imgPromptStrength": 0.8,
"diffusionGuidanceScale": 3.5,
"additionalLoraIntensity": 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
The ability to generate images from text prompts using Cognitive Actions presents an invaluable tool for developers looking to enhance their applications with custom visuals. By streamlining the image creation process, it not only saves time but also allows for greater creative freedom.
As you explore the potential of this action, consider how you can integrate it into your projects to meet your specific needs—be it for marketing, content creation, or interactive applications. The next step is to experiment with your own text prompts and see the magic unfold!