You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a Python client for Replicate. It lets you run models from your Python code or Jupyter notebook, and do various other things on Replicate.
3
+
This is a Python client for [Replicate](https://replicate.com). It lets you run models from your Python code or Jupyter notebook, and do various other things on Replicate.
4
4
5
-
Grab your token from [replicate.com/account](https://replicate.com/account) and authenticate by setting it as an environment variable:
5
+
## Install
6
+
7
+
```sh
8
+
pip install replicate
9
+
```
10
+
11
+
## Authenticate
12
+
13
+
Before running any Python scripts that use the API, you need to set your Replicate API token in your environment.
14
+
15
+
Grab your token from [replicate.com/account](https://replicate.com/account) and set it as an environment variable:
6
16
7
17
```
8
-
export REPLICATE_API_TOKEN=[token]
18
+
export REPLICATE_API_TOKEN=<your token>
9
19
```
10
20
11
-
You can run a model and get its output:
21
+
We recommend not adding the token directly to your source code, because you don't want to put your credentials in source control. If anyone used your API key, their usage would be charged to your account.
22
+
23
+
## Run a model
24
+
25
+
Create a new Python file and add the following code:
12
26
13
27
```python
14
-
$ python
15
-
>>>import replicate
16
-
>>> model = replicate.models.get("stability-ai/stable-diffusion")
Some models, like [replicate/resnet](/replicate/resnet), receive images as inputs. To pass a file as an input, use a file handle or URL
36
+
Some models, like [methexis-inc/img2prompt](https://replicate.com/methexis-inc/img2prompt), receive images as inputs. To pass a file as an input, use a file handle or URL:
23
37
24
38
```python
25
-
>>> model = replicate.models.get("replicate/resnet")
26
-
>>> version = model.versions.get("dd782a3d531b61af491d1026434392e8afb40bfb53b8af35f727e80661489767")
Set the `REPLICATE_API_TOKEN` environment variable to your API token. For example, run this before running any Python scripts that use the API:
136
-
137
-
```
138
-
export REPLICATE_API_TOKEN=<your token>
139
-
```
140
-
141
-
We recommend not adding it directly to your source code, because you don't want to put your API in source control. If anyone uses your API key, their usage would be charged to your account.
142
-
143
-
If you have access to the API, [you can find your API key on your dashboard when signed in](https://replicate.com).
0 commit comments