Create Stunning Jewelry Images with AI Inpainting Actions

26 Apr 2025
Create Stunning Jewelry Images with AI Inpainting Actions

In the world of jewelry design and marketing, visuals play a crucial role in attracting customers and showcasing products. The "Jewelery" service offers powerful Cognitive Actions that simplify the image generation process, allowing developers to create stunning, customized images with minimal effort. By using advanced inpainting techniques combined with style control, this service enables the generation of unique jewelry images tailored to specific design prompts. Whether you need to enhance existing images, visualize new designs, or create promotional content, these actions streamline the workflow and produce high-quality results swiftly.

Common use cases include generating product images for online stores, creating marketing materials, and visualizing design concepts before production. With the ability to control various image properties, developers can ensure that the final output meets branding requirements and aesthetic preferences.

Prerequisites

To get started, you will need a Cognitive Actions API key and a basic understanding of how to make API calls.

Generate Image with Inpainting and Style Control

This action generates custom images using inpainting techniques, allowing for precise style control via image masks and textual prompts. It utilizes models optimized for detailed generation or faster results, accommodating various image properties such as aspect ratio, quality, and format.

Input Requirements

  • prompt: The text prompt guiding the image generation (required).
  • mask: URI of the image mask for inpainting (optional).
  • image: URI of the input image for inpainting or image-to-image generation (optional).
  • width and height: Specify dimensions for custom aspect ratios (optional).
  • goFast: A boolean to enable faster predictions with a speed-optimized model (optional).
  • numOutputs: Number of images to generate (between 1 and 4).
  • guidanceScale: Influences the diffusion process during generation.
  • imageAspectRatio: Defines the aspect ratio of the output image.
  • imageOutputFormat: Select the desired file format for the output image (e.g., webp, jpg, png).
  • Additional parameters for fine-tuning the output include seed, extra LoRA weights, and more.

Expected Output

The action returns a URI of the generated image, which can be used directly in your applications or marketing materials.

Example Output:

  • https://assets.cognitiveactions.com/invocations/9801128c-7bec-4e83-8770-2734d88de77e/14cb7e7b-801e-4db6-95e1-8b2a64ab49d7.webp

Use Cases for this Specific Action

  • Product Visualization: Generate high-quality product images for jewelry listings, enhancing their appeal to potential buyers.
  • Marketing Materials: Create visually striking images for advertisements or social media campaigns, ensuring your jewelry stands out.
  • Design Exploration: Visualize new jewelry designs based on specific prompts, aiding designers in refining their creations before production.
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 = "02a5c5f6-abb0-4137-97cf-895db5f4c7a4" # Action ID for: Generate Image with Inpainting and Style Control

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "mask": "https://replicate.delivery/pbxt/LszpJlOnGl90RzrAdYPkH9KYiOndk5QiPGgd4ScQtclbx1bW/half_face_mask.jpg",
  "image": "https://replicate.delivery/pbxt/LszpJFAYg7uSOVr6FAKkQ4jcelOr5PxBPtF2GwZbtVxNSKOF/half-face.jpg",
  "prompt": "TOK",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 28,
  "imageOutputQuality": 90
}

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 Cognitive Actions offered by the "Jewelery" service empower developers to create stunning, customized jewelry images efficiently. By leveraging inpainting techniques and style controls, you can enhance product imagery, streamline design processes, and elevate marketing efforts. As you explore these actions, consider how they can be integrated into your workflows to maximize visual impact and attract more customers. Start experimenting with the provided capabilities today to transform your jewelry presentation!