TypeError when filtering prompts for potential unsafe words
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()
What are the steps to reproduce this @benrugg ?
@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"
@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
@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!