Create Unique T-Shirt Designs with the fofr/replicate-tshirt Cognitive Actions

The fofr/replicate-tshirt API offers a powerful set of Cognitive Actions designed for developers looking to integrate image generation capabilities into their applications. With these pre-built actions, you can effortlessly generate custom t-shirt designs featuring a hidden Replicate logo. This guide will walk you through one of the available actions, detailing its functionality, input requirements, and how you can implement it in your application.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of JSON and Python.
- A development environment set up to make HTTP requests.
Generally, authentication works by including your API key in the request headers when invoking the Cognitive Actions. This enables you to securely access the services provided by the API.
Cognitive Actions Overview
Generate Tshirt Design with Hidden Logo
Description: This action allows you to create unique t-shirt designs by generating images that contain a hidden Replicate logo. The generation process is guided by user-defined prompts, and customization options are available, including the number of images, exclusion criteria, and the strength of the logo overlay.
Category: Image Generation
Input
The input for this action conforms to the following schema:
- seed (integer, optional): Sets a fixed integer seed for random number generation to ensure reproducibility of results.
- prompt (string, required): A string prompt that guides the image generation process. Default is "a forest".
- negativePrompt (string, optional): Specifies elements that should be excluded from the image. Default is an empty string.
- numberOfImages (integer, optional): Determines the number of images to generate, ranging from 1 to 10. Default is 1.
- controlIllusionStrength (number, optional): Controls the strength of the logo overlay in the generated images, ranging from 0 (no application) to 3 (full application). Default is 1.35.
Example Input:
{
"prompt": "a mystical forest, black background, svg, design",
"negativePrompt": "text, words, cropped",
"numberOfImages": 2,
"controlIllusionStrength": 1.35
}
Output
The action typically returns an array of URLs pointing to the generated images. Here’s an example of what you might expect:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/dc172397-7bd1-4961-9f5c-9a09aa313628/f0933423-a6cd-4f88-925a-15483cb7adb5.png",
"https://assets.cognitiveactions.com/invocations/dc172397-7bd1-4961-9f5c-9a09aa313628/102f9f80-95bd-4161-b679-fb990510eaff.png"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to invoke the Generate Tshirt Design with Hidden Logo action using a hypothetical Cognitive Actions execution endpoint.
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 = "f3dba0c2-af82-47a8-9fbf-edea65fb46d5" # Action ID for Generate Tshirt Design with Hidden Logo
# Construct the input payload based on the action's requirements
payload = {
"prompt": "a mystical forest, black background, svg, design",
"negativePrompt": "text, words, cropped",
"numberOfImages": 2,
"controlIllusionStrength": 1.35
}
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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the action you want to execute. The payload variable contains the input parameters structured according to the schema. The endpoint URL and request structure are illustrative; ensure you adapt them based on the actual API documentation.
Conclusion
The Generate Tshirt Design with Hidden Logo action provides a straightforward and effective way to create custom t-shirt designs. By leveraging this Cognitive Action, developers can enhance their applications with unique image generation capabilities. Consider exploring various prompts and customization options to fully utilize the potential of this action. Happy coding!