*Unofficial* client for the Stability REST API
Project description
Stability AI
An UNOFFICIAL client library for the stability.ai REST API.
Motivation
The official stability-sdk
is a based on gRPC and also really hard to use. Like look at this, this
ignores setting up the SDK.
from stability_sdk import client
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
answers = stability_api.generate(
prompt="a rocket-ship launching from rolling greens with blue daisies",
seed=892226758,
steps=30,
cfg_scale=8.0,
width=512,
height=512,
sampler=generation.SAMPLER_K_DPMPP_2M
)
for resp in answers:
for artifact in resp.artifacts:
if artifact.finish_reason == generation.FILTER:
warnings.warn(
"Your request activated the API's safety filters and could not be processed."
"Please modify the prompt and try again.")
if artifact.type == generation.ARTIFACT_IMAGE:
global img
img = Image.open(io.BytesIO(artifact.binary))
img.save(str(artifact.seed)+ ".png")
This for loop is magic. You must loop the results in exactly this way or the gRPC library won't work. It's about an unpythonic as a library can get.
My Take
# Set the STABILITY_API_KEY environment variable.
from stabilityai.client import AsyncStabilityClient
from stabilityai.models import Sampler
async def example():
async with AsyncStabilityClient() as stability:
results = await stability.text_to_image(
text_prompt="a rocket-ship launching from rolling greens with blue daisies",
# All these are optional and have sane defaults.
seed=892226758,
steps=30,
cfg_scale=8.0,
width=512,
height=512,
sampler=Sampler.K_DPMPP_2M,
)
artifact = results.artifacts[0]
img = Image.open(artifact.file)
img.save(artifact.file.name)
Additional Nicetieis
-
Instead of manually checking
FINISH_REASON
an appropriate exception will automatically be raised. -
Full mypy/pyright support for type checking and autocomplete.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stabilityai-1.0.5.tar.gz
.
File metadata
- Download URL: stabilityai-1.0.5.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ffb4ba2e39560b44a90d72734cd0f8d67ac6337b2c4e54acebb590f385e788 |
|
MD5 | 3026835fe89931ee38b5106dfa029edf |
|
BLAKE2b-256 | a9f9d45dd0436945a2a4e4597c957d81198cb04eb6658721c8fcf5ae4bc845ab |
File details
Details for the file stabilityai-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: stabilityai-1.0.5-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda4eee6d57c4a70c6cde7a6cd74d5808f5f84ababcec10e93658ad16e635ff0 |
|
MD5 | e4684ff4c41db2853a41ca3d7e747b28 |
|
BLAKE2b-256 | 88b0ca1b81c0c463af2a7a16f6e5d3c0d0259b2876aeb295a7f2b9ffc3592d40 |