Generate Stunning Images with bhirstmedia/bhirst-photo Cognitive Actions

In the evolving realm of artificial intelligence, the ability to generate high-quality images from text prompts has become a game-changer for developers. The bhirstmedia/bhirst-photo API provides a robust set of Cognitive Actions that allow you to create custom images tailored to your specifications. With these pre-built actions, developers can save time and effort while integrating powerful image generation capabilities into their applications.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following prerequisites:
- An API key for accessing the Cognitive Actions platform.
- Basic understanding of JSON and RESTful API calls.
- Familiarity with Python programming for implementing the examples provided.
Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Custom Image
Description: Create a high-quality custom image using various settings such as mask, seed, and prompt. Choose between 'dev' for optimized results with about 28 steps or 'schnell' for faster results with only 4 steps.
Category: image-generation
Input
The input for this action consists of several fields that can be customized. Here's the schema for the input:
- prompt (required): A text description guiding the image generation.
- mask (optional): URI of the image mask for inpainting mode.
- seed (optional): Random seed for consistent outputs.
- image (optional): URI of an input image for image-to-image modes.
- width (optional): Width of the image in pixels (256-1440).
- height (optional): Height of the image in pixels (256-1440).
- numOutputs (optional): Number of images to generate (1-4).
- aspectRatio (optional): Aspect ratio of the generated image.
- outputFormat (optional): File format for output images (webp, jpg, png).
- guidanceScale (optional): Influence strength during the diffusion process (0-10).
- mainLoraScale (optional): Strength of the main LoRA (0-3).
- outputQuality (optional): JPEG and WEBP quality (0-100).
- enableFastMode (optional): Activates faster predictions.
- inferenceModel (optional): Selects mode for inference ('dev' or 'schnell').
- promptStrength (optional): Influence of the prompt in img2img mode (0-1).
- additionalLora (optional): Specifies additional LoRA weights.
- numInferenceSteps (optional): Number of denoising steps (1-50).
- disableSafetyChecker (optional): Option to disable the safety checker.
Example Input:
{
"prompt": "a photo of BHIRST using a thin yellow imac at a desk in a modern office. Looking at the camera with the computer monitor off to the side. Wearing a black sweat shirt and extremely surprised with their mouth open and arms up. Wearing a black hat.",
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "jpg",
"guidanceScale": 3,
"mainLoraScale": 1,
"outputQuality": 80,
"enableFastMode": false,
"inferenceModel": "dev",
"promptStrength": 0.95,
"imageMegapixels": "1",
"numInferenceSteps": 50,
"additionalLoraScale": 1
}
Output
The action typically returns a list of URLs pointing to the generated images.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/4c9effac-cff4-4be4-b723-437365da2167/f67f04b2-3f0a-46c7-8720-193368500e52.jpg"
]
Conceptual Usage Example (Python)
Here’s how you can invoke the Generate Custom Image 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 = "49fae76d-f42a-41bf-9a4e-44ae68ec3a87" # Action ID for Generate Custom Image
# Construct the input payload based on the action's requirements
payload = {
"prompt": "a photo of BHIRST using a thin yellow imac at a desk in a modern office. Looking at the camera with the computer monitor off to the side. Wearing a black sweat shirt and extremely surprised with their mouth open and arms up. Wearing a black hat.",
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "jpg",
"guidanceScale": 3,
"mainLoraScale": 1,
"outputQuality": 80,
"enableFastMode": False,
"inferenceModel": "dev",
"promptStrength": 0.95,
"imageMegapixels": "1",
"numInferenceSteps": 50,
"additionalLoraScale": 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, you replace the COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is specific to the Generate Custom Image action, and the payload is structured according to the input schema.
Conclusion
The bhirstmedia/bhirst-photo Cognitive Actions provide powerful and flexible options for generating images tailored to your needs, enabling you to integrate advanced image generation capabilities into your applications seamlessly. Explore further by experimenting with different prompts, settings, and outputs to see the vast potential of these actions. Happy coding!