Transform Your Images with Style Transfer Cognitive Actions

In the world of digital art and design, the ability to manipulate and enhance images is essential. The Style Transfer Cognitive Actions enable developers to apply the artistic style of one image to another, creating stunning results that can elevate visual content. With this innovative technology, you can enhance images with artistic flair and clarity, making them stand out in a crowded digital landscape.
Imagine taking a photograph and transforming it into a masterpiece reminiscent of your favorite artist’s work, or enhancing a simple graphic with intricate styles that captivate viewers. The applications are endless, from social media content creation and marketing materials to artistic projects and personal portfolios. By integrating Style Transfer into your applications, you can streamline the creative process and produce high-quality visuals quickly and efficiently.
Prerequisites
To get started with Style Transfer, ensure you have a Cognitive Actions API key and a basic understanding of making API calls. This will allow you to leverage the powerful capabilities of the service effectively.
Apply Style Transfer
The Apply Style Transfer action is designed to blend the artistic essence of one image with the content of another. This action not only transfers style but also enhances the final output using Clarity upscaling to ensure high-quality results.
Purpose
This action allows you to apply the artistic style of a chosen image (the style reference) to another image (the content reference). It is particularly useful for creating visually appealing content that requires a unique artistic touch.
Input Requirements
To use this action, you need to provide:
- image: A URI pointing to the input image you want to style (required).
- imageStyle: A URI pointing to the image that provides the style you want to apply (required).
- seed: An optional integer for randomization (default is 1337).
- prompt: A text prompt that guides the image generation (default is "masterpiece, best quality, highres").
- guidanceScale: A number that controls the classifier-free guidance in the generation (default is 8).
- styleStrength: A number indicating how strongly the style image influences the output (default is 0.4).
- negativePrompt: A text prompt specifying features to avoid in the output (default is "worst quality, low quality, normal quality").
- numInferenceSteps: An integer indicating how many denoising steps to take (default is 30).
- structureStrength: A number determining the adherence to the original image's structure (default is 0.6).
Example Input:
{
"seed": 1337,
"image": "https://replicate.delivery/pbxt/Kc2yXWRHLMoISFqcvhuezWd2N6bUhMl6Jde2fTBo2vDzY2iR/betomo16_untitled_big_1179ce222671348965486adae5b99a86ba5af2d4.jpg",
"prompt": "masterpiece, best quality, highres",
"imageStyle": "https://replicate.delivery/pbxt/Kc2uo5xyKGma74Fx3N6YteyEKkSlZXymbY1rbXnE9slntIzd/spirit%20Kopie.jpg",
"guidanceScale": 8,
"styleStrength": 0.4,
"negativePrompt": "worst quality, low quality, normal quality",
"numInferenceSteps": 30,
"structureStrength": 0.6
}
Expected Output
The output will be a URI pointing to the newly generated image that reflects the applied style, resulting in a visually striking piece.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/469a36aa-7134-4274-9f61-660e12d9355c/a7f94a1d-1334-4da1-9c42-da1751aef28d.png"
]
Use Cases for this Action
- Social Media Marketing: Enhance promotional images with artistic styles to attract more engagement.
- Content Creation: Quickly generate unique visuals for blogs or articles, making them visually appealing.
- Artistic Projects: Artists can use this tool to explore new styles and create hybrid artworks effortlessly.
- Graphic Design: Designers can apply different styles to mock-ups or client presentations to showcase possibilities.
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 = "5bc8674d-d994-46e1-a83b-5e04c989bf6b" # Action ID for: Apply Style Transfer
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"seed": 1337,
"image": "https://replicate.delivery/pbxt/Kc2yXWRHLMoISFqcvhuezWd2N6bUhMl6Jde2fTBo2vDzY2iR/betomo16_untitled_big_1179ce222671348965486adae5b99a86ba5af2d4.jpg",
"prompt": "masterpiece, best quality, highres",
"imageStyle": "https://replicate.delivery/pbxt/Kc2uo5xyKGma74Fx3N6YteyEKkSlZXymbY1rbXnE9slntIzd/spirit%20Kopie.jpg",
"guidanceScale": 8,
"styleStrength": 0.4,
"negativePrompt": "worst quality, low quality, normal quality",
"numInferenceSteps": 30,
"structureStrength": 0.6
}
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 Cognitive Actions provide developers with a powerful tool to create visually stunning images that resonate with audiences. By leveraging this technology, you can enhance your creative projects, streamline your workflow, and ultimately deliver higher quality content. Take the next step by integrating Style Transfer into your applications and watch your visuals come to life like never before!