Create Stunning Images from Text with Kolors

26 Apr 2025
Create Stunning Images from Text with Kolors

In the realm of digital creativity, the ability to transform text prompts into photorealistic images can be a game-changer for developers and artists alike. Kolors, with its advanced diffusion model, empowers users to generate stunning visual content from simple textual descriptions. This service not only simplifies the image creation process but also offers extensive customization options, allowing for tailored results that meet specific project needs. Whether you're building an application that requires visual content, enhancing marketing materials, or exploring artistic pursuits, Kolors provides the tools to bring your ideas to life seamlessly.

Prerequisites

Before you start using Kolors, ensure you have a Cognitive Actions API key and a basic understanding of making API calls. With these in hand, you're ready to unlock the full potential of image generation.

Generate Photorealistic Image with Kolors

The "Generate Photorealistic Image with Kolors" action is designed to create high-quality images based on user-defined text prompts. It addresses the challenge of visualizing concepts that may be difficult to illustrate manually, offering a quick and efficient solution for generating imagery.

Input Requirements

To utilize this action, you need to provide the following parameters:

  • Width: The desired width of the output image (1 to 2048 pixels).
  • Height: The desired height of the output image (1 to 2048 pixels).
  • Prompt: A descriptive text prompt that guides the image generation (e.g., "A man with hoodie on, illustration").
  • Random Seed: An optional integer to set the seed for random number generation.
  • Guidance Scale: A float value that influences how closely the generated image adheres to the prompt (0 to 20, default is 6.5).
  • Denoising Steps: An integer indicating the number of denoising iterations (1 to 50, default is 25).
  • Negative Prompt: An optional description of elements to exclude from the image.
  • Num Images: The number of images to generate (1 to 4, default is 1).
  • Randomness Factor: A float that controls the level of randomness during the generation (0 to 1, default is 0).

Expected Output

The output will be a URL link to the generated image, allowing you to easily access and utilize the visual content created.

Example output:

["https://assets.cognitiveactions.com/invocations/8646f0a6-936e-4336-bb49-3fb309daee8c/7bb9dd8c-6b90-448d-8fe8-2af8080cbcc3.png"]

Use Cases for this Action

  • Content Creation: Ideal for bloggers, marketers, and social media managers looking to generate unique images for their content without the need for graphic design skills.
  • Prototyping and Mockups: Designers can quickly visualize concepts and ideas, aiding in the development of pitches and presentations.
  • Game Development: Game developers can create concept art or character designs based on descriptive prompts, streamlining the creative process.
  • Educational Tools: Educators can produce illustrative materials that align with their teaching content, enhancing the learning experience.
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 = "55404ac6-ca88-42a2-b1ab-03f1ae69ecb1" # Action ID for: Generate Photorealistic Image with Kolors

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1024,
  "height": 1024,
  "prompt": "A man with hoodie on, illustration",
  "guidanceScale": 6.5,
  "denoisingSteps": 25,
  "numberOfImages": 1,
  "randomnessFactor": 0
}

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

Kolors offers a powerful and flexible solution for generating photorealistic images from text prompts, catering to a variety of applications across different industries. With its customizable parameters, developers can create tailored visuals that meet specific needs and enhance their projects. Whether you're looking to enrich your content, streamline design processes, or explore new creative avenues, Kolors is an invaluable tool in the digital toolkit. Start integrating Kolors into your workflow today and unlock the potential of AI-driven image generation.