SOLVED: Stability-sdk error

Hello !

I’m a beginner with touch and I’m following this tutorial to create an image library with Stable Diffusion API :

Perhaps people here already followed it too.
I’ve installed Python 3.9.5 and work with the standard version of Touch : 2022.33910.
I used Anaconda prompt to pip install stability sdk.

I think (but not sure) the problem is that Touchdesigner and python mismatch.
Here the error I get :

Traceback (most recent call last):
File “/project1/base_stable_diffusion/parexec1”, line 23, in onPulse
td.tdError: File “/project1/base_stable_diffusion/text_apiCall”, line 16
File “C:\Program Files\Derivative\TouchDesigner\bin\lib\site-packages\stability_sdk\”, line 137, in init
raise ValueError(f"key is required for {host}")
ValueError: key is required for
Results of run operation resulted in exception.

What is and why he give back error ?

Please if someone can help. It could be fantastic.


Do you have an API Key ? Did you set it?

Yes I have an API Key.

BUT on the tutorial the part you referenced doesn’t exist.

Here how does it look like in touch TextDAT :
#Paste your API Key below
os.environ[‘STABILITY_KEY’] = op(‘text_apiKey’).text

#Set up our connection to the API.
stability_api = client.StabilityInference(
key=os.environ[‘STABILITY_KEY’], # API Key reference.
verbose=True, # Print debug messages.
engine=“stable-diffusion-xl-1024-v1-0”, # Set the engine to use for generation.
In the part # Paste your API Key below :
I don’t understand the fonction of op(‘text_apiKey’).text because on touch the textDAT named “text_apiKey” remain empty. :face_with_raised_eyebrow: (really followed the tutorial carefully)

In the part # Set up our connection to the API.
The guy in tutorial say to change nothing.

Now, thanks to the link you shared me I’ve set a stability-sdk folder. The python -m stability_sdk generate “A stunning house” command is working well but I don’t think it match with the purpose on tutorial.
On python39, my folder is named stability_sdk.
On the link you shared me the folder generated is named stability-sdk.
I’ve linked the content of both.
If I replace stability_sdk folder by stability-sdk folder on my python site-package path, Touchdesigner give me back another error :
Traceback (most recent call last):
File “/project1/base_stable_diffusion/parexec1”, line 23, in onPulse
td.tdError: File “/project1/base_stable_diffusion/text_apiCall”, line 5
ImportError: cannot import name ‘client’ from ‘stability_sdk’ (unknown location)

Really lost here :laughing:

Other options FYI
If python is not your thing, this implementation is basically plug and play, very easy to get going.

If you want to try a full featured Stable Diffusion component that run local on your computer, but requires python and some setup, I recommend this. I found the steps very easy to follow, at least moreso than the documentation.

Finally found the solution with my tutorial.
Just have to past my API_key on the text_apiKey DAT :man_facepalming:

But thaaanks a lot for sharing yours. It will be useful too !

I pasted my API key into the text_apiKey DAT and got a similar error:

File “/project1/base_stable_diffusion/parexec1”, line 23, in onPulse
AttributeError: ‘NoneType’ object has no attribute ‘run’
(File “/project1/base_stable_diffusion/parexec1”)

Can someone help please?

By the sound of it you are calling run on some object that doesn’t exist.

Did you rename something or have a typo somewhere maybe?

Copy the content of parexec1 here?

If you share your file we can help further.

cc @jackdilaura

Hi there! Thank you so much for the timely reply!

I did have a typo in DAT and after fixing it, i had another ModuleNotFound Error:no module named stability_sdk. But when I run pip list, I got stability-sdk 0.8.4, meaning I had it installed right?

Turned out my pillow is in different path from stability-sdk, so i needed to reinstall pillow and install image as well, and it worked!!! Thank you :laughing: