Transform Your Images with Style Transfer Cognitive Actions

Cognitive Actions' "Style Transfer II" offers a powerful way for developers to enhance images by applying artistic styles and creative transformations. By leveraging advanced AI models, these actions allow users to turn ordinary photographs into stunning artwork, all while providing flexibility to customize the output. Whether you're working on a personal project, developing a mobile app, or enhancing content for social media, Style Transfer actions can simplify your workflow and elevate the visual appeal of your images.
Imagine a scenario where a designer wants to create a unique promotional image for a new product. Using the style transfer capabilities, they can input a standard product photo and apply a trendy artistic style, making it stand out in a crowded marketplace. This not only saves time but also allows for creative experimentation without needing extensive graphic design skills.
Prerequisites
To get started with Style Transfer II, you will need a Cognitive Actions API key and a basic understanding of making API calls.
Generate Style Transferred Image
The "Generate Style Transferred Image" action utilizes Remodela AI's sophisticated style transfer model to transform an input image according to a specified artistic prompt. This action is designed to solve the challenge of creating visually appealing images that resonate with specific themes or styles.
Input Requirements:
- Image: A URI pointing to the input image you want to transform.
- Prompt: A descriptive text that guides the style application, such as "modern interior living room."
- Strength: A value indicating how much alteration should occur, ranging from 0 (minimal change) to 1 (complete transformation).
- Additional Parameters: Options like
loraScale,scheduler,inputImage,inputScale, and more to fine-tune the output.
Expected Output: The output will be a URI of the newly generated image that reflects the artistic style applied to the input image.
Use Cases for this specific action:
- Marketing and Branding: Create visually striking promotional materials that capture attention.
- Social Media Content: Enhance posts with unique artistic styles that differentiate your content.
- Artistic Experimentation: Allow artists and designers to explore new styles and aesthetics without traditional constraints.
- Personal Projects: Transform family photos or personal art into something unique and shareable.
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 = "5055bae5-f0da-4d41-878c-e95d9386e389" # Action ID for: Generate Style Transferred Image
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"image": "https://replicate.delivery/pbxt/KbUKCMMihGkSc5MXYYYkjEI6hlf1GNmGgwugu6JfSQATqiCN/3d.jpeg",
"prompt": "modern interior living room",
"strength": 1,
"loraScale": 0.9,
"scheduler": "K_EULER",
"inputImage": "https://replicate.delivery/pbxt/KbUKD3uoQjyTzdWbeAqYrypl0RWVJc0gI5UHHa3yYWNaqIoc/DALL%C2%B7E%202024-03-20%2017.57.33%20-%20Create%20a%20professional%20photograph%20of%20a%20modern%20interior%20design.%20This%20image%20should%20capture%20a%20living%20room%20space%20that%20combines%20contemporary%20elegance%20with%20c.webp",
"inputScale": 1,
"guidanceScale": 4,
"resizingScale": 1,
"applyWatermark": true,
"negativePrompt": "",
"backgroundColor": "#A2A2A2",
"numberOfOutputs": 1,
"cannyConditionScale": 0.5,
"depthConditionScale": 0.5,
"numberOfInferenceSteps": 30
}
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 Style Transfer actions offer developers a unique opportunity to enhance their applications with creative image transformations. By automating the process of style application, these actions save time and provide endless possibilities for creative expression. As you explore these capabilities, consider the diverse applications in marketing, art, and personal projects. Start integrating Style Transfer today to elevate your visual content to new heights!