Generate Stunning Images with the extrange/qinxiang Cognitive Actions

In the realm of image generation, the extrange/qinxiang API offers a remarkable set of Cognitive Actions that empower developers to create visually captivating images. One of its standout actions, "Generate Handsome Man Photos," allows for highly customizable photo generation, enabling users to specify parameters such as image resolution, style, and prompts. This article will delve into the capabilities of this action, guiding you through its integration into your applications.
Prerequisites
Before you can start using the Cognitive Actions in the extrange/qinxiang API, you will need to have the following:
- An API key for accessing the Cognitive Actions platform.
- Familiarity with making HTTP requests and handling JSON data.
Authentication typically involves including your API key in the request headers, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Handsome Man Photos
Purpose: This action generates photos of the most handsome man on Earth with customizable parameters, offering a unique blend of creativity and control over the generated images.
Category: Image Generation
Input
The input schema for this action includes several fields that allow for detailed customization of the image. Below is a breakdown of the required and optional parameters:
- Mask (string, optional): URI of the input mask for inpaint mode.
- Seed (integer, optional): Random seed for generation. Leave blank for a random seed.
- Image (string, optional): URI of the input image for img2img or inpaint modes.
- Width (integer, default: 1024): Width of the output image in pixels.
- Height (integer, default: 1024): Height of the output image in pixels.
- Prompt (string, default: "An astronaut riding a rainbow unicorn"): Descriptive text guiding the generation.
- Lora Scale (number, default: 0.6): Scale factor for LoRA additive effect.
- Scheduler (string, default: "K_EULER"): Algorithm for scheduling inference steps.
- Custom LoRA Weights (string, optional): URI for custom LoRA weights.
- Guidance Scale (number, default: 7.5): Coefficient for classifier-free guidance.
- Apply Watermark (boolean, default: true): Indicates if a watermark should be applied.
- Negative Prompt (string, optional): Elements to exclude from generation.
- Prompt Strength (number, default: 0.8): Strength of the prompt application.
- Number of Outputs (integer, default: 1): How many images to generate (max 4).
- Refinement Steps (integer, optional): Number of refinement steps for the base image refiner.
- Refinement Style (string, default: "no_refiner"): Style of refinement to use.
- High Noise Fraction (number, default: 0.8): Fraction of noise applied by the expert ensemble refiner.
- Number of Inference Steps (integer, default: 50): Steps for denoising during generation.
- Disable Safety Checker (boolean, default: false): Enable or disable the safety checker.
Example Input:
{
"width": 1024,
"height": 1024,
"prompt": "profile of TOK, formal wear, professional photograph, DSLR",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"refinementStyle": "no_refiner",
"highNoiseFraction": 0.8,
"numInferenceSteps": 50
}
Output
Upon successfully invoking the action, you will receive an array of URLs pointing to the generated images. Here’s an example of the output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/cc3fc991-edb6-40bd-808f-feddf73969a8/841b851d-2685-4951-af22-2cde148279f3.png",
"https://assets.cognitiveactions.com/invocations/cc3fc991-edb6-40bd-808f-feddf73969a8/70b29ff8-70cd-469a-8719-09e99c56e2a6.png",
"https://assets.cognitiveactions.com/invocations/cc3fc991-edb6-40bd-808f-feddf73969a8/4af74ac5-7f86-42e2-9505-a9989ba46775.png",
"https://assets.cognitiveactions.com/invocations/cc3fc991-edb6-40bd-808f-feddf73969a8/7ee90cd1-832e-4554-adb1-dfcd6ec212ee.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python snippet demonstrating how to call the "Generate Handsome Man Photos" action:
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 = "7a9f5ec3-e6b3-4d20-aff1-4f0e868c79c7" # Action ID for Generate Handsome Man Photos
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "profile of TOK, formal wear, professional photograph, DSLR",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": True,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"refinementStyle": "no_refiner",
"highNoiseFraction": 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, make sure to replace the API key and endpoint with your actual values. The JSON payload is structured according to the action's input schema, allowing for a seamless integration.
Conclusion
The extrange/qinxiang API provides developers with powerful tools for image generation, particularly through its "Generate Handsome Man Photos" action. The ability to customize parameters ensures that you can create unique and tailored images for a variety of applications. To dive deeper, consider exploring additional features and actions within the API to enhance your projects further. Happy coding!