Create Stunning Fanhua Style Images with chuanzi/fanhu_style_lora_sdxl Cognitive Actions

24 Apr 2025
Create Stunning Fanhua Style Images with chuanzi/fanhu_style_lora_sdxl Cognitive Actions

In the realm of image generation, the chuanzi/fanhu_style_lora_sdxl Cognitive Actions offer developers a robust toolset for creating visually captivating images inspired by the unique Fanhua style. By leveraging these pre-built actions, you can easily integrate sophisticated image generation capabilities into your applications without needing deep expertise in AI or image processing. This article will guide you through the available action, its usage, and provide conceptual examples to help you get started.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform. This key will be used for authentication when making requests.
  • A basic understanding of JSON format, as you'll be constructing JSON payloads for your requests.

Authentication is typically achieved by passing your API key in the headers of your requests, allowing secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Fanhua Style Images

The Generate Fanhua Style Images action allows you to create images in the distinctive Fanhua style using various input parameters. This action supports both inpainting and img2img modes, providing options for refining styles, customizing output, and fine-tuning the generation process.

Input

The input schema for this action consists of several fields, both required and optional. Here’s a breakdown:

FieldTypeDescription
maskstringURI of the input mask for inpaint mode.
seedintegerRandom seed for image generation. Leave empty for randomization.
imagestringURI of the input image for img2img or inpaint mode.
widthintegerDesired width of the output image (defaults to 1024).
heightintegerDesired height of the output image (defaults to 1024).
promptstringTextual prompt for image generation (defaults to a whimsical astronaut riding a unicorn).
refinestringSpecifies the style to refine the image (options: no_refiner, expert_ensemble_refiner, base_image_refiner).
loraScalenumberScale for LoRA adjustments (range: 0 to 1).
schedulerstringAlgorithm for image scheduling (defaults to K_EULER).
numOutputsintegerNumber of images to generate (1-4).
loraWeightsstringDefines specific LoRA weights to utilize.
refineStepsintegerSteps for refinement when using base_image_refiner.
guidanceScalenumberScale for classifier-free guidance (range: 1 to 50, defaults to 7.5).
highNoiseFracnumberFraction of noise for expert ensemble refining (range: 0 to 1).
applyWatermarkbooleanEnables watermarking for generated images (defaults to true).
negativePromptstringGuides generation away from unwanted elements.
promptStrengthnumberStrength of the prompt in img2img or inpaint modes (range: 0 to 1).
numInferenceStepsintegerIncremental steps in the denoising process (range: 1 to 500, defaults to 50).
disableSafetyCheckerbooleanOption to disable the safety checker on generated images.

Here is an example of a JSON payload for this action:

{
  "width": 1024,
  "height": 1024,
  "prompt": "in style of fanhua,a fashion girl, pov",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}

Output

Upon successful execution, the action typically returns a list of generated image URLs. For example:

[
  "https://assets.cognitiveactions.com/invocations/742134ac-b351-4a52-8467-bd4c297c9aec/58de2c09-f2fd-4594-9fe9-5423abe8dfc4.png"
]

Conceptual Usage Example (Python)

The following Python snippet illustrates how you could call the Cognitive Actions execution endpoint to generate an image using the Fanhua style:

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 = "bf198c17-d664-42a9-9469-4ac770270300" # Action ID for Generate Fanhua Style Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "in style of fanhua,a fashion girl, pov",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": true,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numInferenceSteps": 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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the action's requirements, and the response will include the generated image URLs if successful.

Conclusion

The chuanzi/fanhu_style_lora_sdxl Cognitive Action for generating Fanhua style images provides an accessible way for developers to create stunning visual content. By utilizing the provided input parameters and structure, you can effectively tailor the image generation process to meet your application’s needs. Explore the fascinating world of style-based image generation and integrate these capabilities into your projects for enhanced creativity and engagement!