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
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,39 @@ asyncio.run(main())
68
68
69
69
Functionality between the synchronous and asynchronous clients is otherwise identical.
70
70
71
+
## Running models
72
+
73
+
```python
74
+
import replicate
75
+
76
+
output = replicate.run(
77
+
"black-forest-labs/flux-schnell", input={"prompt": "astronaut riding a rocket like a horse"}
78
+
)
79
+
80
+
# Write the output to a file
81
+
for index, item inenumerate(output):
82
+
withopen(f"output_{index}.webp", "wb") asfile:
83
+
file.write(item.read())
84
+
```
85
+
86
+
`replicate.run()` raises `ModelError` if the prediction fails. You can access the exception's `prediction` property to get more information about the failure:
87
+
88
+
```python
89
+
import replicate
90
+
from replicate import ModelError
91
+
92
+
try:
93
+
output = replicate.run(
94
+
"stability-ai/stable-diffusion-3", input={"prompt": "An astronaut riding a rainbow unicorn"}
95
+
)
96
+
except ModelError as e:
97
+
if"(some known issue)"in e.prediction.logs:
98
+
pass
99
+
print("Failed prediction: "+ e.prediction.id)
100
+
```
101
+
102
+
By default the client will wait up to 60 seconds for the prediction to complete. The timeout can be configured by passing `wait=x` where `x` is a timeout in seconds between 1 and 60. To disable waiting, pass `wait=False`.
103
+
71
104
## Using types
72
105
73
106
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
0 commit comments