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
claude =replicate.use("anthropic/claude-4-sonnet")
562
562
563
563
images = flux_dev(prompt="a cat wearing an amusing hat")
564
564
@@ -570,7 +570,7 @@ print(str(result)) # "This shows an image of a cat wearing a hat ..."
570
570
To create an individual prediction that has not yet resolved, use the `create()` method:
571
571
572
572
```
573
-
claude = use("anthropic/claude-4-sonnet")
573
+
claude = replicate.use("anthropic/claude-4-sonnet")
574
574
575
575
prediction = claude.create(prompt="Give me a recipe for tasty smashed avocado on sourdough toast that could feed all of California.")
576
576
@@ -579,13 +579,49 @@ prediction.logs() # get current logs (WIP)
579
579
prediction.output() # get the output
580
580
```
581
581
582
-
You can access the underlying URL for a Path object returned from a model call by using the `get_path_url()` helper.
582
+
### Downloading file outputs
583
+
584
+
Output files are provided as Python [os.PathLike](https://docs.python.org/3.12/library/os.html#os.PathLike) objects. These are supported by most of the Python standard library like `open()` and `Path`, as well as third-party libraries like `pillow` and `ffmpeg-python`.
585
+
586
+
The first time the file is accessed it will be downloaded to a temporary directory on disk ready for use.
587
+
588
+
Here's an example of how to use the `pillow` package to convert file outputs:
images = flux_dev(prompt="a cat wearing an amusing hat")
597
+
for i, path inenumerate(images):
598
+
with Image.open(path) as img:
599
+
img.save(f"./output_{i}.png", format="PNG")
600
+
```
601
+
602
+
For libraries that do not support `Path` or `PathLike` instances you can use `open()` as you would with any other file. For example to use `requests` to upload the file to a different location:
images = flux_dev(prompt="a cat wearing an amusing hat")
611
+
for path in images:
612
+
withopen(path, "rb") as f:
613
+
r = requests.post("https://api.example.com/upload", files={"file": f})
614
+
```
615
+
616
+
### Accessing outputs as HTTPS URLs
617
+
618
+
If you do not need to download the output to disk. You can access the underlying URL for a Path object returned from a model call by using the `get_path_url()` helper.
0 commit comments