sddebz / stable-diffusion-krita-plugin

GNU Affero General Public License v3.0
423 stars 34 forks source link

Updates the server/client architecture to allow for remote servers #35

Open InconsolableCellist opened 2 years ago

InconsolableCellist commented 2 years ago

Many environments (like mine) have my ML environment and Krita client on separate computers. This update now has the server save all images locally and then respond to remote requests to fetch/save images/masks, allowing for the plugin to run remotely.

InconsolableCellist commented 2 years ago

b3b5fbb also fixes inpainting

InconsolableCellist commented 2 years ago

I had to resolve merge conflicts and it looks like some code got accidentally removed. I believe I've added it all back now, and changed the constant MODE_SD_UPSCALE from 3 to 2

sddebz commented 2 years ago

So thank you for fixes. I looked at the PR again and I see that it doesn't really work in my Krita. I think the problem is it tries to import requests library. Until now I only used standard python library and Krita's libs. Right now I'm not sure how to proceed. I don't want to force users to do some manual steps like installing request lib in pykrita folder or globally. At the same time I don't see how to easly replace requests with urllib.request for this scenario.

So in short, I can't really merge it now because it requires requests library. Maybe you will be able to find a way to remove this depencency or provide a clear and easy way to install missing dependencies for Krita.

sddebz commented 2 years ago

To he honest, I was already working on adding remote server support. I was going to just send file as base64 string in json. I think if we don't find a good solution here, I'll be able to add this feature next weekend. But I'll be happy to merge your version if we make sure it will work for everyone.

InconsolableCellist commented 2 years ago

Oh true, because Krita uses its own Python env you have to copy or link your system libs to Krita.

E.g., on Linux:

cp -R /usr/lib/python3/dist-packages/urllib3 ~/.local/share/krita/pykrita/
cp -R /usr/lib/python3/dist-packages/six.py ~/.local/share/krita/pykrita/
cp -R /usr/lib/python3/dist-packages/chardet ~/.local/share/krita/pykrita/
cp -R /usr/lib/python3/dist-packages/certifi ~/.local/share/krita/pykrita/
cp -R /usr/lib/python3/dist-packages/idna ~/.local/share/krita/pykrita/
cp -R /usr/lib/python3/dist-packages/requests ~/.local/share/krita/pykrita/

I had tried to use just urllib whatever the default lib is, but it doesn't seem to handle file transfers very well. You could do it with base64, that would make for a neater install at least.

In that case you could replace /saveimg on the server with one that accepts base64 in the body, it should be as easy as changing line 325 in krita_diff.py to something like this:

with open(path, "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read())
urllib.request.urlopen(url, encoded_string)

I didn't test that though, but it's a good idea to workaround the lib issue.

I think the fix in 7d9a15d for inpainting is good too.

What me to try base64 encoding as an alternative?

sddebz commented 2 years ago

Well, I would say just let me fix it. I'll have time to do it on saturday.

InconsolableCellist commented 2 years ago

Any progress on this? My changes still work; I've been using them daily.

sddebz commented 2 years ago

I'm sorry. Due to funny actions of my president, I'm currently unable to finish this work. I hope I will be able to look at it this week.