Create Stunning Images Effortlessly with Sdxl Foundation

26 Apr 2025
Create Stunning Images Effortlessly with Sdxl Foundation

In the dynamic landscape of digital content creation, the ability to generate customized images quickly and efficiently is becoming increasingly important. The Sdxl Foundation offers powerful Cognitive Actions that enable developers to harness the potential of advanced image generation techniques. By utilizing the LoRA (Low-Rank Adaptation) model, you can create unique images tailored to specific prompts or modify existing images through img2img and inpainting modes. This flexibility not only speeds up the creative process but also simplifies the workflow, allowing for a more intuitive integration of image generation into applications.

Common Use Cases:

  1. Creative Content Generation: Perfect for artists and designers looking to quickly prototype visuals based on specific themes or ideas.
  2. Game Development: Use the image generation capabilities to create assets for characters, environments, or promotional materials.
  3. Marketing and Advertising: Generate eye-catching visuals for campaigns that require rapid iterations or customization.
  4. Social Media: Create unique graphics that engage audiences and enhance brand presence.

To start using the Sdxl Foundation, you will need an API key and a basic understanding of making API calls.

Generate Image with LoRA Foundation

The "Generate Image with LoRA Foundation" action allows you to create customized images using a LoRA model based on the Foundation. This action supports both img2img and inpainting modes, offering adjustable parameters such as prompt strength, scheduling type, and more.

Purpose

This action solves the problem of creating high-quality, tailored images that meet specific requirements. Whether you want to generate an entirely new image or modify an existing one, this action provides the necessary tools to achieve your vision.

Input Requirements

  • Mask (URI): For inpainting mode, specify a mask where black areas remain unchanged and white areas are targeted for inpainting.
  • Seed (Integer): A random seed value for generating images. Leave blank for a randomized seed.
  • Image (URI): The input image used in img2img or inpaint mode.
  • Width (Integer): Width of the output image in pixels (default is 1024).
  • Height (Integer): Height of the output image in pixels (default is 1024).
  • Prompt (String): Text prompt guiding the image generation process.
  • LoRA Scale (Number): Scale factor for LoRA, ranging from 0 to 1 (default is 0.6).
  • LoRA Weights (String): Weights to utilize for LoRA (leave blank for default).
  • Guidance Scale (Number): Classifier-free guidance scale (default is 7.5).
  • Apply Watermark (Boolean): Toggle for applying a watermark (enabled by default).
  • Negative Prompt (String): Text prompt for elements to avoid in the image.
  • Prompt Strength (Number): Strength of the prompt impact (ranges from 0 to 1).
  • Number of Outputs (Integer): Specifies the number of generated images (minimum is 1, maximum is 4).
  • Refinement Steps (Integer): Number of refinement steps used by the base image refiner.
  • Refinement Style (String): Choose the style of refinement (options include no_refiner, expert_ensemble_refiner, base_image_refiner).
  • High Noise Fraction (Number): Fraction of noise for expert ensemble refiner (default is 0.8).
  • Scheduling Algorithm (String): Algorithm used for scheduling during the generation process (default is K_EULER).
  • Safety Checker Disabled (Boolean): Toggle for disabling the safety checker on generated images.
  • Number of Inference Steps (Integer): Total number of denoising steps (ranges from 1 to 500, default is 50).

Expected Output

The output of this action will be a URI pointing to the generated image, which can be used directly in your applications or shared with your audience.

Example output:

["https://assets.cognitiveactions.com/invocations/1e3a03c5-05f2-4ff1-a5ef-b653d785ff52/c15ddb4c-d9c3-4c51-8b76-cc1442b88703.png"]

Use Cases for this Action

  • Artistic Exploration: Artists can experiment with different prompts and styles, generating multiple iterations of an idea.
  • Product Visualization: Businesses can create promotional images for products, showcasing them in various contexts.
  • Enhanced User Experiences: Applications can leverage this action to provide users with personalized content, adapting images to user preferences or inputs.
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 = "7fd5c6c4-d2d9-48d2-8205-ed9a6f139097" # Action ID for: Generate Image with LoRA Foundation

# 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": 512,
  "prompt": "cinematic scene, close-up of a stormtrooper, debris, crash site of spaceship, dim light, the style of TOK",
  "loraScale": 0.8,
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "overexposed, blur, blurred, blurry, 3D render, CGI",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "refinementStyle": "no_refiner",
  "highNoiseFraction": 0.8,
  "schedulingAlgorithm": "K_EULER",
  "numberOfInferenceSteps": 50
}

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 Sdxl Foundation's image generation capabilities empower developers to create stunning visuals with ease. By leveraging the flexibility of the LoRA model, you can customize images for a variety of applications, from creative projects to marketing initiatives. The ability to fine-tune parameters and generate images on demand not only enhances productivity but also opens up new avenues for creativity. Start integrating these Cognitive Actions into your projects today and unlock the potential of automated image generation.