Create Stunning Drawings from Text with StyleCLIPDraw Actions

In the realm of image generation, the StyleCLIPDraw offers an innovative way to transform text descriptions into artistic drawings. By leveraging the capabilities of Generate Styled Text-to-Drawing, developers can easily create detailed illustrations that capture both the essence of the description and the unique style defined by a reference image. This integration not only simplifies the creative process but also opens up new avenues for artistic expression in applications.
Prerequisites
Before diving into the Cognitive Actions, ensure that you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests, as you'll be sending requests to the API endpoint.
In general, authentication involves including your API key in the request headers, allowing you to securely access the Cognitive Actions services.
Cognitive Actions Overview
Generate Styled Text-to-Drawing
The Generate Styled Text-to-Drawing action enables you to create artistic drawings based on textual prompts while controlling the style with a reference image. This action is particularly useful for applications in art, gaming, and social media where unique visual content is desired.
Input: The action requires a structured input that can include:
- prompt (required): A string describing the desired drawing.
Example:"A monkey dressed up like a cowboy" - styleImage (required): A URI pointing to an image that defines the drawing's style.
Example:"https://replicate.delivery/mgxm/3c8fcad1-c5f6-4af1-a4f6-83e181eb72a9/fruit.jpg" - numberOfPaths (optional): An integer specifying the number of drawing strokes to be used for rendering. Default is 256.
Example:400 - styleStrength (optional): An integer that determines the intensity of the applied style, ranging from 0 (minimal styling) to 100 (maximum styling). Default is 50.
Example:40
Here’s a JSON example of the input payload:
{
"prompt": "A monkey dressed up like a cowboy",
"styleImage": "https://replicate.delivery/mgxm/3c8fcad1-c5f6-4af1-a4f6-83e181eb72a9/fruit.jpg",
"numberOfPaths": 400,
"styleStrength": 40
}
Output: Upon successful execution, the action returns an array of URLs pointing to the generated images. Each image reflects the specified prompt and style. Here’s an example of the output:
[
"https://assets.cognitiveactions.com/invocations/da798fc8-e364-4a2f-9899-16b01c391cd8/5b2ebe6b-32d4-4110-9c5d-d21b90fdadd1.png",
"https://assets.cognitiveactions.com/invocations/da798fc8-e364-4a2f-9899-16b01c391cd8/71af577a-d282-4c53-b99c-ae9ec45cfc95.png",
...
]
Conceptual Usage Example (Python): Here's how you might call the Cognitive Actions execution endpoint using Python. This snippet demonstrates how to structure the input JSON payload and send the request.
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 = "ef01fcef-085e-4371-9e19-f9077f64c945" # Action ID for Generate Styled Text-to-Drawing
# Construct the input payload based on the action's requirements
payload = {
"prompt": "A monkey dressed up like a cowboy",
"styleImage": "https://replicate.delivery/mgxm/3c8fcad1-c5f6-4af1-a4f6-83e181eb72a9/fruit.jpg",
"numberOfPaths": 400,
"styleStrength": 40
}
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 example, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action ID is specified for the Generate Styled Text-to-Drawing action, and the input payload is structured accordingly.
Conclusion
Integrating the Generate Styled Text-to-Drawing action into your applications can significantly enhance the creative capabilities of your projects. By converting text into visually appealing drawings controlled by stylistic references, you can provide users with a unique artistic experience. Explore how you can implement this functionality in your applications and consider experimenting with different prompts and styles to see the diverse outputs generated by this powerful action.