Create Stunning Personalized Images with Bruce Lora

26 Apr 2025
Create Stunning Personalized Images with Bruce Lora

In the world of digital content creation, the ability to generate personalized images can significantly enhance user engagement and storytelling. Bruce Lora offers a powerful Cognitive Action that enables developers to create tailored images based on specific input prompts. This functionality is not only time-efficient but also simplifies the process of generating high-quality visuals that align with user preferences or brand identities.

Imagine a scenario where a marketing team needs to produce customized images for a campaign targeting different demographics. With Bruce Lora, developers can automate this process, ensuring that each generated image resonates with its intended audience. Whether it’s for social media posts, website graphics, or promotional materials, the potential applications of personalized image generation are vast.

Prerequisites

To get started with Bruce Lora, you'll need a Cognitive Actions API key and a fundamental understanding of API calls.

Generate Personalized Image

The "Generate Personalized Image" action is designed to create unique images by leveraging user-defined prompts and advanced image transformation techniques. It supports various customization options such as aspect ratio, image format, and prompt intensity, allowing for a high degree of personalization.

Purpose

This action solves the problem of generating distinct images that cater to specific requirements, whether for marketing, content creation, or artistic endeavors. With the ability to select different models (like 'dev' for detail and 'schnell' for speed), developers can choose the optimal approach for their needs.

Input Requirements

The input for this action must be structured as a CompositeRequest object, which includes the following key properties:

  • prompt (required): A detailed description to guide the image generation.
  • model: Choose between 'dev' for high detail or 'schnell' for faster processing.
  • aspectRatio: Defines the image’s aspect ratio, with options including common formats and a custom setting.
  • outputFormat: Specifies the image format (e.g., webp, jpg, png).
  • Additional parameters include dimensions, guidance scale, and LoRA weights for enhanced customization.

Expected Output

The output will be a series of generated images based on the provided prompt and settings. For example, you may receive URLs of the images in the specified format:

[
  "https://assets.cognitiveactions.com/invocations/11173fac-b693-4aaf-a233-916ef0e5827a/4383617f-3361-45ba-bae6-e29a5fc2c579.png",
  "https://assets.cognitiveactions.com/invocations/11173fac-b693-4aaf-a233-916ef0e5827a/ce4773f8-ef62-4540-9d87-cbc4bd6e1316.png"
]

Use Cases for this Specific Action

  • Marketing Campaigns: Generate tailored images that reflect the brand’s voice and target audience.
  • Social Media: Create eye-catching visuals for posts that require quick turnaround and customization.
  • E-commerce: Personalize product images based on customer preferences or seasonal themes.
  • Content Creation: Enhance articles or blogs with unique imagery that aligns with the written content.
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 = "79f1332d-e3db-4ca7-bc37-606e2194f2ca" # Action ID for: Generate Personalized Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "goFast": false,
  "prompt": "a professional headshot of BRUCEP, shot in a luxurious office setting. BRUCEP is bald, 6'3\", 265 pounds and muscular, not fat. His smile is warm, inviting, and professional. He is a psychologist and hypnotherapist, and his presence invites trust and instant comfort. He is wearing a black button down shirt and tailored grey suit jacket. His skin has a slight tropical tan from a recent vacation.",
  "loraScale": 1,
  "aspectRatio": "16:9",
  "outputFormat": "png",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "approxMegapixels": "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

Bruce Lora’s "Generate Personalized Image" action empowers developers to create customized visuals efficiently, enhancing user experience and engagement across various platforms. By leveraging this Cognitive Action, you can streamline your content creation process and deliver unique, impactful images tailored to your audience’s needs.

As a next step, consider experimenting with different input parameters to discover the full potential of personalized image generation in your projects.