Create Stunning Custom Images with Lexi's Image Generation Action

25 Apr 2025
Create Stunning Custom Images with Lexi's Image Generation Action

In today's digital landscape, the need for unique and tailored visual content is more critical than ever. Lexi's image generation capabilities empower developers to create stunning, customized images through simple input prompts. By harnessing the power of advanced AI, Lexi enables image-to-image conversions and inpainting, allowing you to enhance existing visuals or generate completely new ones. This not only speeds up the creative process but also simplifies the workflow for developers looking to integrate sophisticated image generation features into their applications.

Common use cases for Lexi's image generation include creating marketing materials, enhancing product images, generating artwork for digital platforms, and even producing personalized content for users. Whether you are building an e-commerce platform, a social media tool, or an art generator, Lexi provides the flexibility and power needed to meet diverse creative demands.

To get started, you'll need a Cognitive Actions API key and a basic understanding of how to make API calls.

Generate Image with Lexi

The Generate Image with Lexi action allows users to create customized images based on descriptive prompts. This action addresses the challenge of producing unique images tailored to specific needs, whether for marketing, creative projects, or personal use.

Input Requirements

  • Prompt: A textual description of the desired image content (required).
  • Image: URI of an input image for image-to-image or inpainting mode (optional).
  • Mask: URI for an image mask for inpainting (optional).
  • Width and Height: Dimensions of the generated image in pixels (optional, effective only with custom aspect ratios).
  • Aspect Ratio: The ratio between the width and height of the generated image (default is 1:1).
  • Number of Outputs: Specifies how many images to generate, between 1 and 4.
  • Additional parameters for fine-tuning include seed values, LoRA weights, output quality, and more.

Expected Output

Upon successful execution, the action returns a URI link to the generated image, which can be directly used or displayed in your application.

Use Cases for this Specific Action

  • Marketing Campaigns: Generate unique visuals for social media ads or promotional materials that stand out in crowded feeds.
  • Product Visualization: Create compelling product images that can be customized based on user preferences or seasonal themes.
  • Art Creation: Allow users to generate personalized artwork based on their preferences, enhancing engagement and creativity.
  • Content Enhancement: Use inpainting to modify existing images, such as removing backgrounds or adding elements, making it invaluable for designers.
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 = "242c9368-ded6-453d-8bf4-86dea8b769ea" # Action ID for: Generate Image with Lexi

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1200,
  "height": 1200,
  "prompt": "lexi looking at viewer bold makeup and bold red lips wearing black satin nightgown and colorful hermes patterned silk scarf around neck in a neat knot to the side wit two tapered scarf ends",
  "inferenceModel": "dev",
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 100,
  "additionalLoraScale": 1,
  "imagePromptStrength": 0.8,
  "loraApplicationScale": 1,
  "diffusionGuidanceScale": 3.5,
  "numberofInferenceSteps": 28
}

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

Lexi's image generation capabilities provide developers with a powerful tool for creating tailored visual content quickly and efficiently. Whether you're looking to enhance marketing efforts, generate unique artwork, or improve product visuals, this action enables a plethora of creative possibilities. With its flexible input options and customizable settings, Lexi is well-suited for projects across various industries.

Next steps include exploring how to integrate this action into your applications and experimenting with different prompts and parameters to fully harness the potential of Lexi's image generation capabilities.