Creating Stunning Images with the hasskhan24/hassan Cognitive Actions

In the realm of image generation, the hasskhan24/hassan API provides powerful Cognitive Actions that allow developers to create and enhance images through advanced techniques like inpainting and image-to-image transformations. By leveraging these pre-built actions, you can easily integrate sophisticated image generation capabilities into your applications, enhancing user experience and creativity.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which will be used for authentication.
- Familiarity with making HTTP requests and handling JSON data in your application.
To authenticate your requests, you will typically include your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with Inpainting
Description:
This action allows you to generate images using inpainting and image-to-image transformations. It supports controlled parameters such as aspect ratio, resolution, and quality, utilizing different models for varying inference speeds and quality.
Category: image-generation
Input:
This action requires a prompt field, along with several optional fields that can fine-tune the image generation. Here’s a breakdown of the input schema:
- prompt (string, required): A textual description to guide image generation (e.g., "hassan standing outside talking a selfie with downtown in the background. Only one hassan").
- mask (string, optional): URI of an image mask for inpainting.
- seed (integer, optional): Random seed for reproducibility.
- image (string, optional): URI of an input image for transformations.
- width (integer, optional): Width of the generated image (256-1440 pixels).
- height (integer, optional): Height of the generated image (256-1440 pixels).
- goFast (boolean, optional): Enables faster generation using optimized models.
- imageAspectRatio (string, optional): Specifies the image aspect ratio.
- numOutputs (integer, optional): Number of image outputs (1-4).
- inferenceModel (string, optional): Choose between "dev" and "schnell" models.
- promptStrength (number, optional): Strength of the prompt in transformations.
- imageOutputFormat (string, optional): Output format of the image (webp, jpg, png).
- numInferenceSteps (integer, optional): Number of denoising steps (1-50).
- imageOutputQuality (integer, optional): Quality level of the output image (0-100).
Example Input:
{
"goFast": false,
"prompt": "hassan standing outside talking a selfie with downtown in the background. Only one hassan",
"loraScale": 1,
"numOutputs": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "16:9",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"diffusionGuidanceScale": 3
}
Output: The action typically returns an array of URLs pointing to the generated images. For instance:
[
"https://assets.cognitiveactions.com/invocations/e358282a-f29d-484b-9a62-1b11e2e16a5a/e1d211b4-8581-40c1-83a5-8746dc1fc678.webp"
]
Conceptual Usage Example (Python): Here’s how you might use this action in a Python script:
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 = "1d1ef5c1-c08b-4c95-ab91-e1307e79cd4e" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"goFast": False,
"prompt": "hassan standing outside talking a selfie with downtown in the background. Only one hassan",
"loraScale": 1,
"numOutputs": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "16:9",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"diffusionGuidanceScale": 3
}
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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is crafted based on the required input schema, and the request is sent to the Cognitive Actions endpoint.
Conclusion
The hasskhan24/hassan Cognitive Actions provide a robust framework for generating and enhancing images programmatically. By utilizing these actions, developers can create visually captivating content with minimal effort. Explore various parameters and experiment with different prompts to fully leverage the capabilities of this powerful API. Happy coding!