Generate Personalized Images with LoRA: A Guide to hodeehum/flux-dev-lora-trainer4 Actions

24 Apr 2025
Generate Personalized Images with LoRA: A Guide to hodeehum/flux-dev-lora-trainer4 Actions

In the ever-evolving world of artificial intelligence and image generation, the ability to create personalized images is a game changer for developers. The hodeehum/flux-dev-lora-trainer4 API offers a powerful Cognitive Action that enables developers to generate images based on specific prompts and control various aspects of the image generation process using the LoRA technique. This article will guide you through the capabilities of this action and how to seamlessly integrate it into your applications.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of how to make API calls and handle JSON data.
  • Familiarity with Python programming for the conceptual usage examples provided.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Personalized Images with LoRA

The Generate Personalized Images with LoRA action allows you to create unique images using a model trained with personal photos. This capability includes image-to-image transformations and inpainting, providing you with speed-optimized options for generating images that meet your specific requirements.

  • Category: Image Generation

Input

To use this action, you'll need to construct a JSON payload based on the input schema. The key fields include:

  • prompt (required): A description guiding the image generation.
  • model: Choose between "dev" or "schnell" for different inference speeds.
  • width and height: Define dimensions for the generated image (if using custom aspect ratios).
  • loraScale: Adjusts the intensity of the LoRA application.
  • numberOfOutputs: Specify how many images to generate, with a max of 4.

Here’s an example of a valid input payload:

{
  "model": "dev",
  "width": 1024,
  "height": 1024,
  "prompt": "tjk in a high-resolution, documentary photo as a 34-year-old woman with blonde, chin-length hair, sitting on the grass in a field of flowers.",
  "loraScale": 1,
  "guidanceScale": 10,
  "outputQuality": 100,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "png",
  "numberOfMegapixels": "1",
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 50
}

Output

The action returns a list of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/149f9c02-49e1-44de-b76f-8ee4980758e1/74c1fd2b-5f81-4f69-8af3-c25ccd5ef3b0.png",
  "https://assets.cognitiveactions.com/invocations/149f9c02-49e1-44de-b76f-8ee4980758e1/192f4479-29a7-4f61-bcc0-b4a9536c510e.png",
  "https://assets.cognitiveactions.com/invocations/149f9c02-49e1-44de-b76f-8ee4980758e1/ad71d06a-1fa3-404f-be83-3039f9fac205.png",
  "https://assets.cognitiveactions.com/invocations/149f9c02-49e1-44de-b76f-8ee4980758e1/f80dc211-4e2f-4f62-8417-78647ab33630.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you can call the Generate Personalized Images with 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 = "d532bd32-76cb-4b67-98a9-266333d2a12a"  # Action ID for Generate Personalized Images with LoRA

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 1024,
    "height": 1024,
    "prompt": "tjk in a high-resolution, documentary photo as a 34-year-old woman with blonde, chin-length hair, sitting on the grass in a field of flowers.",
    "loraScale": 1,
    "guidanceScale": 10,
    "outputQuality": 100,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "png",
    "numberOfMegapixels": "1",
    "additionalLoraScale": 1,
    "numberOfInferenceSteps": 50
}

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 code snippet, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and the input payload are structured according to the action's requirements.

Conclusion

The Generate Personalized Images with LoRA action opens up exciting possibilities for developers looking to create tailored images based on unique prompts. By leveraging this action, you can enhance your applications with personalized content that resonates with users. Next, consider experimenting with different prompts and parameters to discover the full potential of this powerful image generation tool. Happy coding!