Relight Portraits Effortlessly with Ic Light's AI Actions

The "Ic Light" service is a powerful tool designed to enhance portrait images by intelligently relighting them based on text descriptions. Utilizing deep learning techniques and the Stable Diffusion v1.5 model, this service simplifies the image enhancement process, allowing developers to automatically create stunning visuals with customizable lighting effects.
Imagine a scenario where a photographer wants to improve the lighting of a portrait taken in suboptimal conditions. With Ic Light, they can provide a descriptive prompt and instantly receive a beautifully relit image, saving time and effort while maintaining high-quality results. This action is ideal for photographers, digital artists, social media managers, and anyone else who relies on striking visuals to capture attention and convey emotion.
Prerequisites
To get started with Ic Light's Cognitive Actions, you'll need an API key for access and a basic understanding of making API calls.
Relight Portraits with Text Guidance
The "Relight Portraits with Text Guidance" action automatically enhances portrait images by applying custom lighting based on user-defined text prompts. This action solves the problem of poor lighting in images by allowing users to specify desired lighting effects, making it easier to create professional-quality visuals.
Input Requirements
- prompt: A text description guiding the relighting and generation process (e.g., "Woman, detailed face, sci-fi RGB glowing, cyberpunk").
- subjectImage: The main foreground image to be relighted (provided as a URI).
- lightSource: Specifies the lighting position applied to the background (options include "Left Light", "Right Light", etc.).
- Additional parameters include
steps,width,height,outputFormat, and various quality settings.
Expected Output
The action returns a URL to the relighted image in the specified format. For example, the output might look like this:
https://assets.cognitiveactions.com/invocations/674ccbf5-dd3a-41ac-b19e-6c3cf0690434/53fa7c87-1761-4d9c-ab58-a0cf32113d38.webp
Use Cases for this Specific Action
- Photography Enhancement: Photographers can quickly improve their portraits without extensive manual editing.
- Content Creation: Social media managers can generate eye-catching images that stand out in feeds.
- Artistic Projects: Digital artists can experiment with different lighting styles to enhance their artwork.
- E-commerce: Businesses can create appealing product images that attract customers by applying the right lighting.
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 = "e3df8a9d-d592-4a7a-8ee2-a25bbf4e146d" # Action ID for: Relight Portraits with Text Guidance
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"steps": 25,
"width": 512,
"height": 640,
"prompt": "Woman, detailed face, sci-fi RGB glowing, cyberpunk",
"lightSource": "Left Light",
"outputFormat": "webp",
"subjectImage": "https://replicate.delivery/pbxt/KtCKrs9sxPF3HciwoWL0TTVM9Nde7ySDWpO9S2flTiyi9Pp3/i3.png",
"outputQuality": 80,
"appendedPrompt": "best quality",
"negativePrompt": "lowres, bad anatomy, bad hands, cropped, worst quality",
"numberOfImages": 1,
"highResolutionScale": 1.5,
"lowResolutionDenoise": 0.9,
"highResolutionDenoise": 0.5,
"classifierFreeGuidance": 2
}
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
With the "Ic Light" service, developers can leverage AI to enhance portrait images effortlessly. The ability to relight images based on descriptive text opens up a world of possibilities for photographers, content creators, and artists alike. By integrating these Cognitive Actions, you can streamline your workflow, produce high-quality visuals, and delight your audience.
To take full advantage of this service, start experimenting with different prompts and lighting configurations to see how Ic Light can transform your images.