Skip to content

Commit 6725e82

Browse files
committed
Consolidate examples
Signed-off-by: Mattt Zmuda <[email protected]>
1 parent 1f441a2 commit 6725e82

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

README.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ Create a new Python file and add the following code:
4242
['https://replicate.com/api/models/stability-ai/stable-diffusion/files/50fcac81-865d-499e-81ac-49de0cb79264/out-0.png']
4343
```
4444

45-
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:
45+
Some models, like [andreasjansson/blip-2](https://replicate.com/andreasjansson/blip-2), have files as inputs.
46+
To run a model that takes a file input,
47+
pass a URL to a publicly accessible file.
48+
Or, for smaller files (<10MB), you can pass a file handle directly.
4649

4750
```python
4851
>>> output = replicate.run(
49-
"salesforce/blip:2e1dddc8621f72155f24cf2e0adbde548458d3cab9f00c0139eea840d0ac4746",
50-
input={"image": open("path/to/mystery.jpg", "rb")},
52+
"andreasjansson/blip-2:f677695e5e89f8b236e52ecd1d3f01beb44c34606419bcc19345e046d8f786f9",
53+
input={ "image": open("path/to/mystery.jpg") }
5154
)
5255

5356
"an astronaut riding a horse"
@@ -79,28 +82,6 @@ Some models, like [methexis-inc/img2prompt](https://replicate.com/methexis-inc/i
7982
> print(results)
8083
> ```
8184
82-
To run a model that takes a file input, pass a URL to a publicly accessible file. Or, for smaller files (<10MB), you can convert file data into a base64-encoded data URI and pass that directly:
83-
84-
```
85-
# Run andreasjansson/blip-2:f677695e by providing an image from local file system which is base64 encoded by files.py
86-
import replicate
87-
import base64
88-
89-
# This reads an example image `gg_bridge.jpeg` from current working directory into a buffer and into the prediction request
90-
with open("gg_bridge.jpeg", "rb") as image_file:
91-
output = replicate.run(
92-
"andreasjansson/blip-2:f677695e5e89f8b236e52ecd1d3f01beb44c34606419bcc19345e046d8f786f9",
93-
input={
94-
"image": image_file,
95-
"caption": False,
96-
"question": "what body of water does this bridge cross?",
97-
"temperature": 1,
98-
"use_nucleus_sampling": False
99-
}
100-
)
101-
print(output)
102-
```
103-
10485
## Run a model and stream its output
10586
10687
Replicate’s API supports server-sent event streams (SSEs) for language models.

0 commit comments

Comments
 (0)