Unleashing Creativity: Integrating Image Generation with DreamShaper-v7 Actions

In the world of AI, the ability to generate stunning images from textual descriptions is revolutionizing creative fields. The DreamShaper-v7 actions provide developers with powerful tools to create images using advanced techniques, including inpainting and img2img transformations. With features like customizable prompts, safety checks, and various scheduling algorithms, these pre-built actions simplify the complexity of image generation, allowing you to focus on your application's unique features.
Prerequisites
Before you can start using the Cognitive Actions provided by DreamShaper-v7, you will need to meet a few general requirements:
- API Key: You will require an API key to authenticate your requests to the Cognitive Actions platform.
- Setup: Ensure you have access to the necessary libraries for making HTTP requests, such as
requestsin Python.
Conceptually, authentication typically involves passing your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with DreamShaper
The Generate Image with DreamShaper action is designed to create images based on textual prompts, utilizing the sophisticated capabilities of the DreamShaper-v7 model. This action supports various features like img2img, inpainting, and safety checks, making it versatile for different creative needs.
Input
The input for this action requires a structured JSON object that can include the following fields:
- mask (string, optional): Input mask for inpaint mode (URI format).
- seed (integer, optional): Random seed for deterministic outputs. E.g.,
3889919804. - image (string, optional): URI of the input image for img2img or inpaint modes.
- width (integer, optional): Width of the output image. Options include 128, 256, 384, ..., up to 1024 (default is 512).
- height (integer, optional): Height of the output image. Same options as width (default is 512).
- prompt (string, required): Text input guiding the image generation. E.g.,
"face close up, fashion photography portrait of indian girl with blue hair...". - scheduler (string, optional): Scheduling algorithm for denoising steps (default is
K_EULER). - guidanceScale (number, optional): Controls the classifier-free guidance (default is 7.5).
- safetyChecker (boolean, optional): Enable or disable the safety checker (default is true).
- negativePrompt (string, optional): Specifications on attributes to avoid in the output.
- promptStrength (number, optional): Influence of the input prompt with an initial image (default is 0.8).
- numberOfOutputs (integer, optional): Number of images to generate (default is 1, maximum is 4).
- numberOfInferenceSteps (integer, optional): Total steps to refine the image, ranging from 1 to 500 (default is 50).
Example Input:
{
"seed": 3889919804,
"width": 576,
"height": 1024,
"prompt": "face close up, fashion photography portrait of indian girl with blue hair, in lush jungle with flowers, 3d render, cgi, symetrical, octane render, 35mm, bokeh, 9:16, (intricate details:1.12), hdr, (intricate details, hyperdetailed:1.15), (natural skin texture, hyperrealism, soft light, sharp:1.2), detailed, sunlight passing through foliage",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 9,
"negativePrompt": "(worst quality:2),(low quality:2),(blurry:2),bad_prompt,text, (bad and mutated hands:1.3),(bad hands),badhandv4,mutated hands, bad anatomy, missing fingers,extra fingers,fused fingers,too many fingers,(interlocked fingers:1.2), extra limbs,malformed limbs,multiple limbs, extra arms, extra legs, long neck, cross-eyed, negative_hand, negative_hand-neg, text, label, caption, nude, nsfw, naked, explicit, porn",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 30
}
Output
The output of this action is a URL pointing to the generated image. The result can vary based on the input parameters but generally adheres to the following format:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/dccc890c-0648-4abb-83f3-2f1eb60b7cf2/272e0ebb-ffe3-45dd-904f-96f9eef42fdf.png"
]
Conceptual Usage Example (Python)
Here's how you might call the Generate Image with DreamShaper 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 = "a5da766b-14b0-44cc-95bf-5ffeed0c249f" # Action ID for Generate Image with DreamShaper
# Construct the input payload based on the action's requirements
payload = {
"seed": 3889919804,
"width": 576,
"height": 1024,
"prompt": "face close up, fashion photography portrait of indian girl with blue hair, in lush jungle with flowers...",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 9,
"negativePrompt": "(worst quality:2),(low quality:2),(blurry:2),bad_prompt,text...",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 30
}
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 placeholder for the API key and action ID with your actual credentials. The payload captures all necessary inputs for the image generation process, and the response is handled to display the result or capture any errors.
Conclusion
The DreamShaper-v7 Cognitive Actions empower developers to easily integrate image generation capabilities into their applications. By leveraging advanced features such as customizable prompts and safety checks, you can create engaging visual content tailored to your needs. As you explore these actions, consider how they can enhance your projects and inspire new creative possibilities. Happy coding!