stabilityai


Namestabilityai JSON
Version 1.0.5 PyPI version JSON
download
home_page
Summary*Unofficial* client for the Stability REST API
upload_time2024-02-22 15:32:01
maintainer
docs_urlNone
author
requires_python>=3.11
licenseGPLv3
keywords stabilityai bot
VCS
bugtrack_url
requirements aiohttp pydantic
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

```python
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

```python
# 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.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "stabilityai",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "stabilityai,bot",
    "author": "",
    "author_email": "Estelle Poulin <dev@inspiredby.es>",
    "download_url": "https://files.pythonhosted.org/packages/a9/f9/d45dd0436945a2a4e4597c957d81198cb04eb6658721c8fcf5ae4bc845ab/stabilityai-1.0.5.tar.gz",
    "platform": null,
    "description": "# Stability AI\n\nAn **UNOFFICIAL** client library for the stability.ai REST API.\n\n## Motivation\n\nThe official `stability-sdk` is a based on gRPC and also really hard to use. Like look at this, this\nignores setting up the SDK.\n\n```python\nfrom stability_sdk import client\nimport stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation\n\nanswers = stability_api.generate(\n    prompt=\"a rocket-ship launching from rolling greens with blue daisies\",\n    seed=892226758,\n    steps=30,\n    cfg_scale=8.0,\n    width=512,\n    height=512,\n    sampler=generation.SAMPLER_K_DPMPP_2M\n)\n\nfor resp in answers:\n    for artifact in resp.artifacts:\n        if artifact.finish_reason == generation.FILTER:\n            warnings.warn(\n                \"Your request activated the API's safety filters and could not be processed.\"\n                \"Please modify the prompt and try again.\")\n        if artifact.type == generation.ARTIFACT_IMAGE:\n            global img\n            img = Image.open(io.BytesIO(artifact.binary))\n            img.save(str(artifact.seed)+ \".png\")\n```\n\nThis for loop is *magic*. You must loop the results in exactly this way or the gRPC library won't\nwork. It's about an unpythonic as a library can get.\n\n## My Take\n\n```python\n# Set the STABILITY_API_KEY environment variable.\n\nfrom stabilityai.client import AsyncStabilityClient\nfrom stabilityai.models import Sampler\n\nasync def example():\n  async with AsyncStabilityClient() as stability:\n    results = await stability.text_to_image(\n        text_prompt=\"a rocket-ship launching from rolling greens with blue daisies\",\n        # All these are optional and have sane defaults.\n        seed=892226758,\n        steps=30,\n        cfg_scale=8.0,\n        width=512,\n        height=512,\n        sampler=Sampler.K_DPMPP_2M,\n    )\n\n    artifact = results.artifacts[0]\n\n    img = Image.open(artifact.file)\n    img.save(artifact.file.name)\n```\n\n## Additional Nicetieis\n\n* Instead of manually checking `FINISH_REASON` an appropriate exception will automatically be\n    raised.\n\n* Full mypy/pyright support for type checking and autocomplete.\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "*Unofficial* client for the Stability REST API",
    "version": "1.0.5",
    "project_urls": {
        "changelog": "https://github.com/estheruary/stabilityai/-/blob/main/CHANGELOG.md",
        "homepage": "https://github.com/estheruary/stabilityai",
        "repository": "https://github.com/estheruary/stabilityai"
    },
    "split_keywords": [
        "stabilityai",
        "bot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "88b0ca1b81c0c463af2a7a16f6e5d3c0d0259b2876aeb295a7f2b9ffc3592d40",
                "md5": "e4684ff4c41db2853a41ca3d7e747b28",
                "sha256": "cda4eee6d57c4a70c6cde7a6cd74d5808f5f84ababcec10e93658ad16e635ff0"
            },
            "downloads": -1,
            "filename": "stabilityai-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e4684ff4c41db2853a41ca3d7e747b28",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 9953,
            "upload_time": "2024-02-22T15:31:59",
            "upload_time_iso_8601": "2024-02-22T15:31:59.202058Z",
            "url": "https://files.pythonhosted.org/packages/88/b0/ca1b81c0c463af2a7a16f6e5d3c0d0259b2876aeb295a7f2b9ffc3592d40/stabilityai-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9f9d45dd0436945a2a4e4597c957d81198cb04eb6658721c8fcf5ae4bc845ab",
                "md5": "3026835fe89931ee38b5106dfa029edf",
                "sha256": "12ffb4ba2e39560b44a90d72734cd0f8d67ac6337b2c4e54acebb590f385e788"
            },
            "downloads": -1,
            "filename": "stabilityai-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "3026835fe89931ee38b5106dfa029edf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 11812,
            "upload_time": "2024-02-22T15:32:01",
            "upload_time_iso_8601": "2024-02-22T15:32:01.263753Z",
            "url": "https://files.pythonhosted.org/packages/a9/f9/d45dd0436945a2a4e4597c957d81198cb04eb6658721c8fcf5ae4bc845ab/stabilityai-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-22 15:32:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "estheruary",
    "github_project": "stabilityai",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "==",
                    "3.8.4"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "1.10.2"
                ]
            ]
        }
    ],
    "lcname": "stabilityai"
}
        
Elapsed time: 3.91332s