Generate Stunning Images with the phillylovesdata/flux_lora Cognitive Actions

23 Apr 2025
Generate Stunning Images with the phillylovesdata/flux_lora Cognitive Actions

In the world of image generation, the phillylovesdata/flux_lora API offers powerful Cognitive Actions that enable developers to create high-quality images using advanced techniques like inpainting and LoRA (Low-Rank Adaptation). These pre-built actions allow for flexibility in aspect ratios, dimensions, and styles, making it easier for developers to integrate stunning visuals into their applications. In this article, we'll explore how to leverage these Cognitive Actions to enhance your projects.

Prerequisites

Before diving into the implementation, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON, as the input and output will be structured in this format.
  • Familiarity with making HTTP requests in your programming language of choice (conceptually illustrated with Python below).

For authentication, you typically pass your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Image with Inpainting and LoRA

The Generate Image with Inpainting and LoRA action allows you to create high-quality images using inpainting techniques. This action provides flexibility in aspect ratio, dimensions, and style guided by LoRA weights. It supports various image formats and adjustable prompt influence and image detail.

Input

The action requires a structured input with several optional fields. Here’s a breakdown of the input schema:

  • prompt (required): A detailed description of the image to be generated.
  • mask (optional): URI of the image mask for inpainting.
  • seed (optional): Random seed for deterministic generation.
  • image (optional): URI for image-to-image processing.
  • model (optional): Choose between "dev" and "schnell" models.
  • width (optional): Width of the image in pixels.
  • height (optional): Height of the image in pixels.
  • aspectRatio (optional): Aspect ratio for the generated image.
  • outputCount (optional): Number of images to generate (1-4).
  • outputFormat (optional): File format for output images (webp, jpg, png).
  • guidanceScale (optional): Influence of the prompt on the image.
  • outputQuality (optional): Quality of the saved image.
  • denoisingSteps (optional): Number of denoising steps during generation.
  • promptStrength (optional): Strength of the prompt when using img2img.
  • loraWeights (optional): Specify LoRA weights using model URIs.
  • loraIntensityScale (optional): Degree to which the main LoRA affects the output.
  • additionalLora (optional): Additional LoRA weights.
  • additionalLoraScale (optional): Influence of additional LoRA on the final image.
  • goFast (optional): Optimize for faster predictions.
  • disableSafetyChecker (optional): Option to disable safety checking.

Here's an example input JSON payload:

{
  "model": "dev",
  "goFast": false,
  "prompt": "A powerful and emotional scene of PhillyAIraGeGaming standing confidently in front of a grand orchestra, passionately singing as the conductor and musicians follow his lead. He is illuminated by dramatic stage lighting, wearing a stylish performance outfit that exudes charisma and presence. The orchestra behind him consists of violinists, cellists, and brass players, all deeply engaged in their performance. The concert hall is majestic, with an elegant design, warm lighting, and an enthusiastic audience captivated by the performance. The atmosphere is filled with energy and emotion, as PhillyAIraGeGaming delivers a breathtaking vocal performance.",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 80,
  "denoisingSteps": 28,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "loraIntensityScale": 1,
  "additionalLoraScale": 1
}

Output

The action typically returns a list of generated image URLs in the specified output format. Here’s an example of a possible output:

[
  "https://assets.cognitiveactions.com/invocations/8be3e767-ecc1-42b4-bd11-20f5a38d4caa/349acd3d-531c-46b2-b6c9-da2915199347.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Inpainting and LoRA action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "f1df3d06-f6d0-4c1c-8a2a-183750778684" # Action ID for Generate Image with Inpainting and LoRA

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "A powerful and emotional scene of PhillyAIraGeGaming standing confidently in front of a grand orchestra, passionately singing as the conductor and musicians follow his lead...",
    "aspectRatio": "1:1",
    "outputCount": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 80,
    "denoisingSteps": 28,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "loraIntensityScale": 1,
    "additionalLoraScale": 1
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the input requirements of the action. The endpoint URL and request structure are illustrative and may vary based on your implementation.

Conclusion

The phillylovesdata/flux_lora Cognitive Actions provide a robust and flexible way to generate stunning images through inpainting and LoRA techniques. By understanding how to integrate these actions into your applications, you can create captivating visuals tailored to your specific needs. Whether you're developing a game, an art application, or any other project that requires high-quality imagery, these actions can significantly enhance your offerings. Start experimenting today and unlock the creative potential of your applications!