Create Stunning Images with the camilo-rojas/camilor Cognitive Actions

In the world of AI and machine learning, image generation has taken a front seat, offering developers powerful tools to bring their creative visions to life. The camilo-rojas/camilor API provides a robust Cognitive Action that allows you to generate images using advanced inpainting techniques. With options for high-quality outputs or faster generation, developers can create customized images based on specific prompts, all while leveraging additional features like LoRA weights for enhanced results. This blog post will guide you through the capabilities of the Generate Image with Inpainting and Custom Model action and how to integrate it into your applications.
Prerequisites
Before you start using the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests and handling JSON data.
- Basic knowledge of Python for executing example code.
You will need to pass your API key in the request headers to authenticate your calls to the Cognitive Actions endpoint.
Cognitive Actions Overview
Generate Image with Inpainting and Custom Model
This action allows you to create detailed images based on a given prompt using sophisticated inpainting techniques. You can choose between two models: the 'dev' model for high-quality images or the 'schnell' model for quicker results. Additionally, you can customize various image attributes, including resolution and aspect ratio, and enhance your images with LoRA weights.
Input
The input schema for this action requires a prompt and includes several optional fields. Below is the schema breakdown along with an example input:
- Required Fields:
- prompt: A detailed text prompt guiding the image generation.
- Optional Fields:
- mask: URI of the image mask for inpainting mode.
- seed: Integer for reproducible image generation.
- image: URI of an input image for image-to-image modes.
- width: Custom width of the generated image (256 to 1440).
- height: Custom height of the generated image (256 to 1440).
- outputCount: Number of images to generate (1 to 4).
- loraWeights: URI for loading additional LoRA weights.
- imageAspectRatio: Specifies the aspect ratio of the generated image.
- imageOutputFormat: Format for the output images (webp, jpg, png).
- imageOutputQuality: Image quality on a scale from 0 to 100.
Example Input:
{
"prompt": "Hyperrealistic portrait of camilor styled as Matt Damon with similar facial features, wearing white movie Interstellar movie spacesuit in three-quarter view through clear futuristic open helmet visor...",
"outputCount": 1,
"loraStrength": 1,
"promptImpact": 0.8,
"denoisingSteps": 28,
"inferenceModel": "dev",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 90,
"additionalLoraStrength": 1,
"processingGuidanceScale": 3.5
}
Output
The action typically returns a list of generated image URLs based on the input prompt. Here’s a sample output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/560558e5-c3d6-44da-ab40-4f11806e67e2/cf8e0c42-6670-4677-aba7-44209605ab62.webp"
]
Conceptual Usage Example (Python)
Here's a conceptual Python code snippet demonstrating how to invoke the Generate Image with Inpainting and Custom Model 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 = "5c2f636f-1f62-44d6-9f1e-2e970842ab66" # Action ID for Generate Image with Inpainting and Custom Model
# Construct the input payload based on the action's requirements
payload = {
"prompt": "Hyperrealistic portrait of camilor styled as Matt Damon...",
"outputCount": 1,
"loraStrength": 1,
"promptImpact": 0.8,
"denoisingSteps": 28,
"inferenceModel": "dev",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 90,
"additionalLoraStrength": 1,
"processingGuidanceScale": 3.5
}
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 COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID is set for the image generation, and the input payload is constructed based on the specified schema. The response is printed in a structured format, showing the generated image URLs.
Conclusion
The Generate Image with Inpainting and Custom Model action from the camilo-rojas/camilor API empowers developers to create highly detailed and customized images. By leveraging the various options available for image generation, including LoRA weights and aspect ratios, you can achieve stunning visual outputs tailored to your specific needs.
As a next step, consider experimenting with different prompts and parameters to see the diverse range of images you can generate, or explore integrating this action into a larger application for dynamic image creation. Happy coding!