nousr / koi

A plug-in for Krita that enables the use of AI models for img2img generation.
MIT License
445 stars 36 forks source link

KeyError: 'HTTP_IMAGE_STRENGTH' on request #22

Closed guumaster closed 2 years ago

guumaster commented 2 years ago

I'm getting this python error on colab server on each request

ERROR:__main__:Exception on /api/img2img [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "<ipython-input-2-d662ef371448>", line 62, in img2img
    strength=float(headers["image_strength"]),
  File "/usr/local/lib/python3.7/dist-packages/werkzeug/datastructures.py", line 1381, in __getitem__
    return _unicodify_header_value(self.environ[f"HTTP_{key}"])
KeyError: 'HTTP_IMAGE_STRENGTH'

This are the requests headers sent from Krita:

HEADERS: 
Host: cc66-35-224-131-209.ngrok.io
User-Agent: Python-urllib/3.8
Transfer-Encoding: chunked
Accept-Encoding: identity
Content-Type: application/octet-stream
Prompt: A beautiful mountain landscape in the style of greg rutkowski, oils on canvas.
Prompt-Strength: 7.5
Seed: 1337
Sketch-Strength: 0.6000000000000001
Steps: 32
X-Forwarded-For: <MY_IP>
X-Forwarded-Proto: http

Any ideas on how to solve this?

guumaster commented 2 years ago

I found the issue in the notebook (or the plugin), the key names doesn't match. To fix this, change this code:

    with autocast("cuda"):
        return_image = pipe(
            init_image=img,
            prompt=headers["prompt"],
-           strength=float(headers["image_strength"]),
+           strength=float(headers["sketch_strength"]),
            guidance_scale=float(headers["prompt_strength"]),
            num_inference_steps=int(headers["steps"]),
        )["sample"][0]`
nousr commented 2 years ago

yes! thank you....i made a boneheaded mistake last night and forgot to update the colab facpalm

nousr commented 2 years ago

thanks :) 1d63055f2f276a55f010a43238f2d1639014f894 should fix it!!