Transform Your Images with Magic Style Transfer Cognitive Actions

In the realm of image processing, the batouresearch/magic-style-transfer API offers powerful capabilities for artistic style transfer. This API enables developers to transform images by applying the artistic style of one image onto another, unlocking endless creative possibilities. By leveraging these pre-built Cognitive Actions, you can enhance your applications with sophisticated image manipulation features without needing extensive background in image processing.
Prerequisites
Before you begin integrating the Cognitive Actions offered by the batouresearch/magic-style-transfer API, ensure you have the following:
- An API key for the Cognitive Actions platform.
- A basic understanding of how to make HTTP requests and handle JSON data.
- Familiarity with Python or your preferred programming language for API integration.
To authenticate with the API, you will typically pass your API key in the request headers. This allows you to securely access the actions provided by the service.
Cognitive Actions Overview
Apply Artistic Style Transfer
The Apply Artistic Style Transfer action allows you to transform an image by applying the artistic style of another image. This is ideal for generating unique visual content that combines different artistic influences.
- Category: Image Processing
Input
The action requires the following parameters in its input schema:
- image (string, required): The URI of the input image.
- prompt (string, optional): A text prompt for image generation, defaulting to "An astronaut riding a rainbow unicorn."
- strength (number, optional): Denoising strength for img2img processing, ranges from 0 to 1.
- loraScale (number, optional): LoRA additive scale affecting image quality, valid between 0 and 1.
- scheduler (string, optional): The name of the scheduler used during inference, defaults to "K_EULER."
- inputImage (string, required): The URI of the input image used in img2img or inpaint mode.
- inputScale (number, optional): Strength of the IP Adapter, valid between 0 and 1.
- guidanceScale (number, optional): Scale for classifier-free guidance, ranges from 1 to 50.
- resizingScale (number, optional): Scaling factor for adding a solid margin to the image.
- applyWatermark (boolean, optional): Applies a watermark to mark generated images.
- negativePrompt (string, optional): A negative prompt to avoid certain features in image generation.
- backgroundColor (string, optional): Color to replace the alpha channel of an input image.
- numberOfOutputs (integer, optional): Specifies the number of images to generate (from 1 to 4).
- conditionCannyScale (number, optional): ControlNet interference level, ranges from 0 to 2.
- conditionDepthScale (number, optional): Depth-based interference level for ControlNet, ranges from 0 to 2.
- numberOfInferenceSteps (integer, optional): Number of denoising steps during inference (from 1 to 500).
Example Input:
{
"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,
"conditionCannyScale": 0.5,
"conditionDepthScale": 0.5,
"numberOfInferenceSteps": 30
}
Output
The action typically returns a list of URLs to the generated images based on the provided input.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/9adbad93-04bf-426d-89fc-5a0e6ccb07bd/984800e8-1019-41d2-813a-d30a401d0b7e.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Apply Artistic Style Transfer action using Python:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "494f8d34-f09f-4e8e-994d-0011cc09cbed" # Action ID for Apply Artistic Style Transfer
# Construct the input payload based on the action's requirements
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,
"conditionCannyScale": 0.5,
"conditionDepthScale": 0.5,
"numberOfInferenceSteps": 30
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
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: {e.response.text}")
In this code snippet, replace the placeholders with your actual API key and modify the input payload as necessary. The action ID and input structure are illustrative and should match the requirements outlined above.
Conclusion
Integrating the batouresearch/magic-style-transfer Cognitive Actions into your applications opens up a world of creative possibilities for image processing. By using the Apply Artistic Style Transfer action, you can easily transform images and create stunning visual content. Whether for artistic projects, marketing materials, or social media content, these actions can significantly enhance the visual appeal of your applications. Explore further use cases and experiment with the input parameters to maximize the potential of this powerful tool!