Create Stunning Custom Images with Happy Drops Part2

26 Apr 2025
Create Stunning Custom Images with Happy Drops Part2

In the ever-evolving world of digital content creation, having the ability to generate customized images quickly and efficiently is a game-changer for developers. "Happy Drops Part2" offers a powerful Cognitive Action that enables users to create unique images through advanced inpainting techniques. By simply providing a prompt and optional image mask, developers gain intricate control over various image attributes, such as aspect ratio, dimensions, and output format. This capability not only enhances creativity but also streamlines the process of generating high-quality visuals tailored to specific needs.

Prerequisites

To get started with Happy Drops Part2, developers will need a Cognitive Actions API key and a basic understanding of API calls.

Generate Custom Image with Mask and Prompt

The "Generate Custom Image with Mask and Prompt" action allows users to create customized images by leveraging inpainting technology. This action solves the common problem of needing tailored visuals that align perfectly with specific concepts or styles.

Input Requirements: To utilize this action, the primary requirement is a prompt that describes the desired image. Additional optional parameters include:

  • mask: An image mask for inpainting.
  • image: An input image for image-to-image conversion or inpainting.
  • aspectRatio: Sets the aspect ratio for the generated image.
  • width and height: Define the dimensions of the image when using a custom aspect ratio.
  • resultFormat: Choose from webp, jpg, or png for the output image format.

Expected Output: The action returns a generated image URL based on the input parameters provided. For example, an output might look like:

https://assets.cognitiveactions.com/invocations/09bb5c2f-16ba-46d8-8fc6-e6e357dd0db6/8c892a20-672b-43d9-b490-60257f3d14d4.png

Use Cases for this specific action:

  • Creative Projects: Developers can use this action to generate bespoke images for marketing materials, websites, or social media posts, ensuring that visuals align with brand identity.
  • Game Development: Create unique assets or backgrounds that fit specific game scenarios, enhancing the player experience.
  • E-commerce: Generate product images featuring different styles or settings, allowing customers to visualize items in diverse contexts.
  • Artistic Exploration: Artists can experiment with prompts to create distinct artworks, pushing the boundaries of their creative expressions.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "803e171e-6435-4c64-bfd0-bfc2a74ff203" # Action ID for: Generate Custom Image with Mask and Prompt

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "goFast": false,
  "prompt": "Bright modern kitchen scene. A bag of ORGNFDRPS2 is on the kitchen table.",
  "aspectRatio": "1:1",
  "resultFormat": "png",
  "loraIntensity": 1,
  "resultQuality": 100,
  "inferenceModel": "dev",
  "imageResolution": "1",
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "guidanceIntensity": 3,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The "Happy Drops Part2" Cognitive Action for generating custom images is an invaluable tool for developers looking to enhance their digital content creation capabilities. With its ability to produce tailored visuals through simple prompts, this action opens up a wide array of possibilities across various industries. Whether for marketing, gaming, e-commerce, or artistic endeavors, the benefits of quick and customized image generation are clear. Developers are encouraged to experiment with different prompts and parameters to unlock the full potential of this powerful tool.