Create Stunning QR Codes with lucataco/illusion-diffusion-hq Cognitive Actions

25 Apr 2025
Create Stunning QR Codes with lucataco/illusion-diffusion-hq Cognitive Actions

In today's digital landscape, QR codes are an essential tool for bridging the physical and digital worlds. The lucataco/illusion-diffusion-hq API provides a powerful set of Cognitive Actions designed to help developers generate visually appealing and highly customizable QR codes. By leveraging advanced image generation techniques, this API not only simplifies the process of creating QR codes but also allows for unique artistry in their design. In this blog post, we will explore the main Cognitive Action available in this spec and how you can easily integrate it into your applications.

Prerequisites

To get started with the Cognitive Actions provided by the lucataco/illusion-diffusion-hq API, you will need:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and HTTP requests.
  • A development environment set up to make API calls (e.g., Python with the requests library).

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate QR Code with Realistic Vision

The Generate QR Code with Realistic Vision action allows you to create visually stunning QR codes by utilizing the Monster Labs QrCode ControlNet on top of SD Realistic Vision v5.1. This action integrates advanced image generation techniques to produce unique QR code designs with high quality and detail. You can customize various elements such as the dimensions, guidance scale, and background color to tailor the QR code's appearance.

Input

The input schema for this action requires several fields, with some being mandatory. Here’s a breakdown of the required and optional fields:

  • prompt (required): A string that guides the QR code generation.
  • seed (optional): An integer for random seed generation (default is -1 for a random seed).
  • image (optional): A URI for an input image; if not provided, a QR code will be generated.
  • width (optional): The width of the output image in pixels (default is 768).
  • border (optional): QR code border size (default is 1, must be between 0 and 4).
  • height (optional): The height of the output image in pixels (default is 768).
  • guidanceScale (optional): A scale factor for classifier-free guidance (default is 7.5, range: 0.1 to 30).
  • qrCodeContent (optional): The content or URL that the QR code should link to.
  • negativePrompt (optional): Terms to avoid during image generation (default is "ugly, disfigured, low quality, blurry, nsfw").
  • numberOfOutputs (optional): The number of images to generate (default is 1, range: 1 to 4).
  • qrCodeBackground (optional): Background color of the QR code (default is "gray").
  • numberOfInferenceSteps (optional): Number of diffusion steps for image generation (default is 40, range: 20 to 100).
  • controlnetConditioningScale (optional): Scaling factor for ControlNet outputs (default is 1, range: 0 to 4).

Example Input:

{
  "seed": 1057727382,
  "image": "https://replicate.delivery/pbxt/Ja8F0jwa45Bv8AxkH0VjcyhQ4KTN0RJiLYivSskJmeCWc30n/spiral.png",
  "width": 768,
  "border": 1,
  "height": 768,
  "prompt": "(masterpiece:1.4), (best quality), (detailed), Medieval village scene with busy streets and castle in the distance",
  "guidanceScale": 7.5,
  "qrCodeContent": "",
  "negativePrompt": "ugly, disfigured, low quality, blurry, nsfw",
  "numberOfOutputs": 1,
  "qrCodeBackground": "gray",
  "numberOfInferenceSteps": 40,
  "controlnetConditioningScale": 1
}

Output

The action typically returns an array of URLs pointing to the generated images. Each URL can be used to access the created QR code.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/6f99f8d7-6d08-4965-ae3a-b0bf85a7c1db/cb753e90-0c77-43c3-b7b6-6d2902dab913.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call this 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 = "54c79853-4835-4636-b704-75c9df0812cd"  # Action ID for Generate QR Code with Realistic Vision

# Construct the input payload based on the action's requirements
payload = {
    "seed": 1057727382,
    "image": "https://replicate.delivery/pbxt/Ja8F0jwa45Bv8AxkH0VjcyhQ4KTN0RJiLYivSskJmeCWc30n/spiral.png",
    "width": 768,
    "border": 1,
    "height": 768,
    "prompt": "(masterpiece:1.4), (best quality), (detailed), Medieval village scene with busy streets and castle in the distance",
    "guidanceScale": 7.5,
    "qrCodeContent": "",
    "negativePrompt": "ugly, disfigured, low quality, blurry, nsfw",
    "numberOfOutputs": 1,
    "qrCodeBackground": "gray",
    "numberOfInferenceSteps": 40,
    "controlnetConditioningScale": 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 code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for generating the QR code is included in the payload. The input JSON structure reflects the requirements outlined earlier, ensuring that the API call is correctly formatted.

Conclusion

The lucataco/illusion-diffusion-hq Cognitive Actions provide an innovative way to create custom and visually appealing QR codes. By utilizing the flexibility of the Generate QR Code with Realistic Vision action, developers can enhance their applications and offer users an engaging experience. Whether you're integrating QR codes for marketing, event management, or digital interactions, this API can significantly streamline your development process.

Explore the capabilities of this API, and start creating stunning QR codes today!