JasonS09 / comfy_sd_krita_plugin

Make AI art between canvas and nodes with Krita.
MIT License
148 stars 7 forks source link

Error when trying to "load prompt from layer" #37

Closed 42degrees closed 9 months ago

42degrees commented 10 months ago

I have not used Krita before today and I installed it only to try to use this plugin, so this could be something I did wrong in the installation process for the plugin. I've been able to get img2img working, but when I load a PNG and then select "Load Prompt from Layer" I get the error below. I tested this with several images. I tested each image by dropping it onto ComfyUI and they all load the workflow just fine. I assume that the prompt is being pulled out of the workflow, so I tried several different workflows, including the default simple workflow, but they all fail. From the final error, "Expecting value: line 1 column 1 (char 0)" my assumption is that it's not getting the JSON from the image at all. Here is the full error, with a screenshot below, if that helps.

JSONDecodeError Python 3.10.7: C:\Program Files\Krita (x64)\bin\krita.exe Wed Nov 15 11:40:48 2023

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\pages\img_base.py in () 107 self.custom_workflow.cfg_connect() 108 self.prompt_layout.cfg_connect() 109 self.prompt_layer_load.released.connect(lambda: self.update_prompt(script.prompt_from_selection())) 110 self.seed_layout.cfg_connect() 111 self.sampler_layout.cfg_connect() self = self.prompt_layer_load = self.prompt_layer_load.released = self.prompt_layer_load.released.connect = self.update_prompt = <bound method SDImgPageBase.update_prompt of > global script = script.prompt_from_selection = <bound method Script.prompt_from_selection of >

C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\script.py in prompt_from_selection(self=) 118 return None 119 120 prompt_info = PromptBase.from_json(self.node.name()) 121 if not prompt_info: 122 self.status_changed.emit(ERR_MISSING_PROMPT) prompt_info undefined global PromptBase = <class 'krita_comfy.prompt.PromptBase'> PromptBase.from_json = self = self.node = self.node.name =

C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\prompt.py in from_json(text='Background') 200 keys = get_members(PromptBase) 201 # Skip text until json starts 202 prompt_data = json.loads(text[text.find('{'):]) 203 for k in keys: 204 setattr(prompt, k, prompt_data[k]) prompt_data undefined global json = <module 'json' from 'C:\Program Files\Krita (x64)\python\python310.zip\json\init.pyc'> json.loads = text = 'Background' text.find =

C:\Program Files\Krita (x64)\json__init__.py in loads(s='d', cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw={})

C:\Program Files\Krita (x64)\json\decoder.py in decode(self=, s='d', _w=)

C:\Program Files\Krita (x64)\json\decoder.py in raw_decode(self=, s='d', idx=0)

JSONDecodeError: Expecting value: line 1 column 1 (char 0) cause = None class = <class 'json.decoder.JSONDecodeError'> context = StopIteration(0) delattr = <method-wrapper 'delattr' of JSONDecodeError object> dict = {'colno': 1, 'doc': 'd', 'lineno': 1, 'msg': 'Expecting value', 'pos': 0} dir = doc = None eq = <method-wrapper 'eq' of JSONDecodeError object> format = ge = <method-wrapper 'ge' of JSONDecodeError object> getattribute = <method-wrapper 'getattribute' of JSONDecodeError object> gt = <method-wrapper 'gt' of JSONDecodeError object> hash = <method-wrapper 'hash' of JSONDecodeError object> init = <bound method JSONDecodeError.init of JSONDe...ror('Expecting value: line 1 column 1 (char 0)')> init_subclass = <built-in method init_subclass of type object> le = <method-wrapper 'le' of JSONDecodeError object> lt = <method-wrapper 'lt' of JSONDecodeError object> module = 'json.decoder' ne = <method-wrapper 'ne' of JSONDecodeError object> new = reduce = <bound method JSONDecodeError.reduce of JSON...ror('Expecting value: line 1 column 1 (char 0)')> reduce_ex = <built-in method reduce_ex of JSONDecodeError object> repr = <method-wrapper 'repr' of JSONDecodeError object> setattr = <method-wrapper 'setattr' of JSONDecodeError object> setstate = sizeof = str = <method-wrapper 'str' of JSONDecodeError object> subclasshook = __suppress_context = True traceback = weakref__ = None args = ('Expecting value: line 1 column 1 (char 0)',) colno = 1 doc = 'd' lineno = 1 msg = 'Expecting value' pos = 0 with_traceback =

The above is a description of an error in a Python program. Here is the original traceback:

Traceback (most recent call last): File "C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\pages\img_base.py", line 109, in self.prompt_layer_load.released.connect(lambda: self.update_prompt(script.prompt_from_selection())) File "C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\script.py", line 120, in prompt_from_selection prompt_info = PromptBase.from_json(self.node.name()) File "C:\Users\Scott Gartner\AppData\Roaming\krita\pykrita\krita_comfy\prompt.py", line 202, in from_json prompt_data = json.loads(text[text.find('{'):]) File "json__init__.py", line 346, in loads File "json\decoder.py", line 337, in decode File "json\decoder.py", line 355, in raw_decode json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

image

JasonS09 commented 10 months ago

I've been able to get img2img working, but when I load a PNG and then select "Load Prompt from Layer"

I think you're misunderstanding the "Load Prompt from Layer" functionality. It's not for loading the workflow from a Comfy image.

This button will only work when you have a group layer selected, product of a previous generation. It's intended to reproduce all the data of that specific generation in your plugin so you can do it again without having to manually configure it.

The plugin automatically crafts the required workflow for each mode when you press the "Start" button. If you want to inject more complex workflows (a totally optional feature), you can do that in your "workflow" tab, although by the way how ComfyUI handles the nodes with ids can be a bit tricky. I suggest reading the wiki of this repo to clear your doubts.

42degrees commented 10 months ago

Thanks Jason, I appreciate your clearing that up for me. Though I was confused about what it was supposed to do, it still threw an exception instead of telling me what I did wrong (even if I thought it was going to do something else).

JasonS09 commented 10 months ago

Yes, you're right. Exception should be handled now.