-
Notifications
You must be signed in to change notification settings - Fork 0
feat(client): first pass at .run() helper #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
741df3a
cfcf1a7
36a65e6
38cdddc
ffdaeda
c6f76bb
4a25c43
85d1942
00723b4
46b1f8d
b969e71
7b1a1cc
c9f34c5
1804f7c
c80c7f3
82fe905
eaf0a07
6824251
eadfb53
cf383c6
24d30f4
11e09d3
0257edf
00970c0
c7216db
80b28fc
a5c02d4
aef2230
0ec2897
2143731
0beb9ef
c9c4b8c
ad4da10
e8af3f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import rich | ||
|
|
||
| from replicate import Replicate | ||
|
|
||
| client = Replicate() | ||
|
|
||
| outputs = client.run( | ||
| "black-forest-labs/flux-schnell", | ||
| input={"prompt": "astronaut riding a rocket like a horse"}, | ||
| ) | ||
| rich.print(outputs) | ||
| for index, output in enumerate(outputs): | ||
| with open(f"output_{index}.webp", "wb") as file: | ||
| file.write(output.read()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import asyncio | ||
|
|
||
| from replicate import AsyncReplicate | ||
|
|
||
| client = AsyncReplicate() | ||
|
||
|
|
||
| # https://replicate.com/stability-ai/sdxl | ||
| model_version = "stability-ai/sdxl:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b" | ||
| prompts = [f"A chariot pulled by a team of {count} rainbow unicorns" for count in ["two", "four", "six", "eight"]] | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| # Create tasks with asyncio.gather directly | ||
| tasks = [client.run(model_version, input={"prompt": prompt}) for prompt in prompts] | ||
|
|
||
| results = await asyncio.gather(*tasks) | ||
| print(results) | ||
|
|
||
|
|
||
| asyncio.run(main()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ dependencies = [ | |
| "anyio>=3.5.0, <5", | ||
| "distro>=1.7.0, <2", | ||
| "sniffio", | ||
| "asyncio>=3.4.3", | ||
|
||
| ] | ||
| requires-python = ">= 3.8" | ||
| classifiers = [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.