Stability-AI / stability-sdk

SDK for interacting with stability.ai APIs (e.g. stable diffusion inference)
https://platform.stability.ai/
MIT License
2.43k stars 339 forks source link

Specifying the seed value results in an error #16

Closed mikr closed 2 years ago

mikr commented 2 years ago

Specifying the seed value does not work at the moment and results in an exception inside protobuf:

File "/Users/michael/Projects/genv/dreamstudio/venv/lib/python3.9/site-packages/google/protobuf/internal/containers.py", line 166, in extend elem_seq_iter = iter(elem_seq) TypeError: 'int' object is not iterable

As protobuf always expects an interable (there is a long standing TODO item at the crash site) this can be trivially fixed by adding an else case at https://github.com/Stability-AI/stability-sdk/blob/main/src/stability_sdk/client.py#L213 that wraps the seed value in a list.

    if not seed:
        seed = [random.randrange(0, 4294967295)]
    else:
        seed = [seed]

Because even the latest version of protobuf does not support this union handling properly, the line at https://github.com/Stability-AI/stability-sdk/blob/main/src/stability_sdk/client.py#L185 could be simplified to:

    seed: Sequence[int] = (0,),
tmattoneill commented 2 years ago

I had this same issue in the standard python implementation. Wrapping the seed value in a list did the trick there, too (after hours of googling and neglecting to look here first).

dmarx commented 2 years ago

current version of the client takes care of this for you