Create Stunning Images with the fargmancarl/rosemary Cognitive Actions

In the realm of artificial intelligence, the ability to generate images has become a powerful tool for developers. The fargmancarl/rosemary API offers a robust set of Cognitive Actions designed to create high-quality images using advanced techniques like inpainting and customizable generation parameters. These pre-built actions simplify the integration of image generation capabilities into your applications, providing exciting possibilities for creative projects, content creation, and more.
Prerequisites
To get started with the fargmancarl/rosemary Cognitive Actions, you'll need to ensure you have the following:
- API Key: You'll need a valid API key to authenticate your requests to the Cognitive Actions platform. This key typically needs to be passed in the headers of your API requests.
- Environment Setup: Ensure that your development environment supports making HTTP requests (e.g., using libraries like
requestsin Python).
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows developers to create detailed and realistic images. This action supports features like inpainting with an optional mask, customizable aspect ratios, and model selection for optimal or fast image generation. It allows the specification of various parameters such as width, height, prompt strength, and output quality.
Input
This action requires the following input fields:
- prompt (required): A descriptive text that guides the image generation.
- mask (optional): An image mask for inpainting mode.
- seed (optional): An integer for setting a random seed, ensuring reproducibility.
- image (optional): An input image for image-to-image or inpainting mode.
- model (optional): Select between "dev" or "schnell" for inference.
- aspectRatio (optional): Define the aspect ratio of the generated image.
- width (optional): Specifies the width of the generated image (when aspect ratio is custom).
- height (optional): Specifies the height of the generated image (when aspect ratio is custom).
- additional fields: Include options for output format, guidance scale, and more.
Here’s an example input payload:
{
"model": "dev",
"goFast": false,
"prompt": "A dramatic photo realistic cinematic image of Rosie confidently yielding a giant sword, getting ready to challenge a real life ferocious and angry dragon with flame and smoke rising from the dragons nostrils. They are in a very colorful seemingly fairytale forest. Fuji Velvia 50 (Reversal Film). Heavy 35 mm film grain.",
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"loraIntensity": 1,
"outputQuality": 80,
"promptStrength": 0.1,
"resolutionSize": "1",
"numberOfOutputs": 1,
"inferenceStepCount": 28,
"additionalLoraIntensity": 1
}
Output
The output will typically return a URL to the generated image. For example:
[
"https://assets.cognitiveactions.com/invocations/3157bc3d-7500-4230-a9e3-503b7df09403/03329cfc-9572-43b1-a91f-034cc123378b.webp"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet that demonstrates how to call the Generate Image with Inpainting 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 = "06afbd01-c8bc-4e07-8772-984c18003498" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "A dramatic photo realistic cinematic image of Rosie confidently yielding a giant sword, getting ready to challenge a real life ferocious and angry dragon with flame and smoke rising from the dragons nostrils. They are in a very colorful seemingly fairytale forest. Fuji Velvia 50 (Reversal Film). Heavy 35 mm film grain.",
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"loraIntensity": 1,
"outputQuality": 80,
"promptStrength": 0.1,
"resolutionSize": "1",
"numberOfOutputs": 1,
"inferenceStepCount": 28,
"additionalLoraIntensity": 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 snippet, you’ll notice that the action ID and the input payload are structured correctly for the hypothetical API call. The endpoint URL and request format are illustrative, emphasizing the need to tailor them to your actual implementation.
Conclusion
The fargmancarl/rosemary Cognitive Actions, particularly the Generate Image with Inpainting action, empower developers to create stunning visuals with ease. By leveraging these capabilities, you can enhance your applications with rich imagery and engage your users more effectively. Whether for artistic endeavors or practical applications, these tools open up exciting possibilities. Start experimenting with these actions today and unlock the full potential of your creative ideas!