Skip to content
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

TypeError when filtering prompts for potential unsafe words #125

Open
benrugg opened this issue Nov 10, 2022 · 4 comments
Open

TypeError when filtering prompts for potential unsafe words #125

benrugg opened this issue Nov 10, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@benrugg
Copy link

benrugg commented Nov 10, 2022

Using this prompt generates a TypeError in utils.truncate_fit: Cute young boy playing with an adorable dragon puppy by a stream in a sunny daylight forest

I'm all for filtering potentially unsafe words/images, but I'm assuming the expected behavior is to return an error message of some kind, rather than throwing the error.

Here is the error log:

2022-11-10 20:41:30,615 INFO client.py(265) - Opening channel to grpc.stability.ai:443
2022-11-10 20:41:30,653 INFO client.py(265) - Channel opened to grpc.stability.ai:443
2022-11-10 20:41:30,933 INFO client.py(265) - Sending request.
2022-11-10 20:41:31,282 INFO client.py(265) - Got 97f15955-6e0a-4346-8b19-96225c5b12ad with ['ARTIFACT_TEXT', 'ARTIFACT_IMAGE'] in 0.35s
2022-11-10 20:41:31,283 INFO client.py(265) - wrote ARTIFACT_TEXT to /tmp/Cute young boy playing with an adorable dragon puppy by a stream in a sunny daylight forest_1668112891_0.pb.json
Traceback (most recent call last):
  File "/var/lang/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/var/lang/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/var/task/stability_sdk/client.py", line 520, in <module>
    for artifact in artifacts:
  File "/var/task/stability_sdk/client.py", line 129, in process_artifacts_from_answers
    out_p = truncate_fit(prefix, prompt, ext, int(artifact_start), idx, MAX_FILENAME_SZ)
  File "/var/task/stability_sdk/client.py", line 56, in truncate_fit
    prompt_budget -= len(ext) + 1
TypeError: object of type 'NoneType' has no len()
@dmarx dmarx added the bug Something isn't working label Nov 15, 2022
@gacogo
Copy link

gacogo commented Nov 17, 2022

What are the steps to reproduce this @benrugg ?

@benrugg
Copy link
Author

benrugg commented Nov 17, 2022

@convexholl just run like normal. I think I've only tested it with img2img:

python -m stability_sdk.client -W 512 -H 512 --steps 40 --cfg_scale 7.0 --sampler k_lms --prefix /tmp/ --seed 1218574063 --init_image /tmp/image.png --start_schedule 0.5 "Cute young boy playing with an adorable dragon puppy by a stream in a sunny daylight forest"

@gacogo
Copy link

gacogo commented Nov 18, 2022

@benrugg Your issue seems to be coming from here ext = mimetypes.guess_extension(artifact.mime) . While testing this, it seems that the buffer doesn't come with descriptor in some cases. One fix would be to use a library like magic to get the mimetype from the binary. Could you try this:

replace line 88 of stability_sdk/client.py with the following 2 lines.

mime_type = magic.from_buffer(artifact.binary, mime=True) #gets you the mimetype
ext = mime_type.split('/')[1])
Let me know if this works for you. I might also add that it seems to occur when using init_image option. Probably little to do with unsafe words themselves

@benrugg
Copy link
Author

benrugg commented Nov 18, 2022

@convexholl thank you for looking into this. I appreciate this answer, but I'm not necessarily looking to fork the stability sdk to fix this issue just for me. I was hoping to raise this so it can be addressed for everyone!

gacogo added a commit to gacogo/stability-sdk that referenced this issue Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants