Replicate text2img
This handler was implemented using the replicate
library that is provided by Replicate.
The required arguments to establish a connection are,
- model_name: Model name which you want to access in MindsDB. e.g ‘air-forever/kandinsky-2’
- version: version hash/id which you want to use in MindsDB.
- api_key: API key from Replicate Platform you can found here.
Before you can use Replicate, it’s essential to authenticate by setting your API token in an environment variable named REPLICATE_API_TOKEN. This token acts as a key to enable access to Replicate’s features.
- Using pip:
If you’re working in a standard Python environment (using pip for package management), set your token as an environment variable by running the following command in your terminal:
On Linux, Mac:
On Windows:
- Using Docker:
For Docker users, the process slightly differs. You need to pass the environment variable directly to the Docker container when running it. Use this command:
Again, replace ‘YOUR_TOKEN’ with your actual Replicate API token.
Usage
To use this handler and connect to a Replicate cluster in MindsDB, you need an account on Replicate. Make sure to create an account by following this link.
To establish the connection and create a model in MindsDB, use the following syntax:
You can use the DESCRIBE PREDICTOR query to see the available parameters that you can specify to customize your predictions:
Output
Now, you can use the established connection to query your ML Model as follows:
OUTPUT
- IMPORTANT NOTE: PREDICTED URL will only work for 24 hours after prediction.
Note: Replicate provides only a few free predictions, so choose your predictions wisely. Don’t let the machines have all the fun, save some for yourself! 😉