huchenlei / sd-webui-openpose-editor

Openpose editor for ControlNet. Full hand/face support.
MIT License
653 stars 65 forks source link

[Bug]: Not working with RunPod #27

Closed ak74fire closed 1 year ago

ak74fire commented 1 year ago

Is there an existing issue for this?

What happened?

When WebUI is served via https, the editor cannot be loaded.

Steps to reproduce the problem

  1. Load A1111 WebUI from https
  2. Upload any image and run OpenPose preprocessor
  3. Click 'edit' in preprocessor preview
  4. sd-webui-openpose-editor won't load (only blank popup)

What should have happened?

sd-webui-openpose-editor should load properly when WebUI is served via https.

Commit where the problem happens

webui: v1.3.2 controlnet: v1.1.220 (2598ca9e78f167014c6556cb89dab792a745749f) openpose-editor: 8843a7e10c96a13f93b9f37ca16b3e39d8a4fcda

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--opt-sdp-attention --port 3000 --listen --enable-insecure-extension-access

Console logs

2023-06-19T05:40:16.655422611Z Launching Web UI with arguments: -f --opt-sdp-attention --port 3000 --listen --enable-insecure-extension-access
2023-06-19T05:40:16.655428674Z No module 'xformers'. Proceeding without it.
2023-06-19T05:40:16.655434936Z 2023-06-19 05:40:16,654 - ControlNet - INFO - ControlNet v1.1.220
2023-06-19T05:40:16.759052762Z ControlNet preprocessor location: /workspace/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2023-06-19T05:40:16.759086344Z 2023-06-19 05:40:16,758 - ControlNet - INFO - ControlNet v1.1.220
2023-06-19T05:40:18.063265705Z Loading weights [07934daabe] from /workspace/stable-diffusion-webui/models/Stable-diffusion/majicmixLux_v1.safetensors
2023-06-19T05:40:18.063301038Z *Deforum ControlNet support: enabled*
2023-06-19T05:41:44.319144943Z Running on local URL:  http://0.0.0.0:3000
2023-06-19T05:41:44.319192075Z 
2023-06-19T05:41:44.319199585Z To create a public link, set `share=True` in `launch()`.
2023-06-19T05:41:44.319206666Z Startup time: 6.7s (import torch: 1.3s, import gradio: 1.7s, import ldm: 0.4s, other imports: 0.7s, setup codeformer: 0.3s, load scripts: 1.1s, create ui: 0.9s, gradio launch: 0.4s).
2023-06-19T05:41:44.319213204Z Creating model from config: /workspace/stable-diffusion-webui/configs/v1-inference.yaml
2023-06-19T05:41:44.319219558Z LatentDiffusion: Running in eps-prediction mode
2023-06-19T05:41:44.319225451Z DiffusionWrapper has 859.52 M params.
2023-06-19T05:41:44.319231225Z Applying optimization: sdp... done.
2023-06-19T05:41:44.319237257Z Textual inversion embeddings loaded(3): badhandv4, easynegative, ng_deepnegative_v1_75t
2023-06-19T05:41:44.319243560Z Model loaded in 4.4s (load weights from disk: 1.5s, create model: 0.7s, apply weights to model: 0.9s, apply half(): 0.5s, load VAE: 0.4s, move model to device: 0.3s).
2023-06-19T05:41:44.319255022Z 2023-06-19 05:41:44,318 - ControlNet - INFO - Preview Resolution = 512

Browser logs

Mixed Content: The page at 'https://xxxx:3000/' was loaded over HTTPS, but requested an insecure resource 'http://100.65.14.206:60892/openpose_editor_index/'. This request has been blocked; the content must be served over HTTPS.
openpose_editor.js?1686250245.0:3 Uncaught (in promise) TypeError: Failed to fetch
    at checkEditorAvailable (openpose_editor.js?1686250245.0:3:23)
    at openpose_editor.js?1686250245.0:99:1

Additional information

No response

Procyon1996 commented 1 year ago

same problem here

huchenlei commented 1 year ago

Do you have any additional setup of an web server proxy?

The editor is setup to use relative path /openpose_editor_index. According to the log messages, you are running WebUI locally on port 3000, but the editor is accessing port 60892.

There is nothing I can do in the repo as it is already relative path. You would need to figure out why the FastAPI route /openpose_editor_index is not served with HTTPS in your setup.

ak74fire commented 1 year ago

The WebUI is running behind a RunPod proxy: https://docs.runpod.io/docs/expose-ports

It maps internal URL http://127.0.0.1:3000 to external URL like https://{POD_ID}-{INTERNAL_PORT}.proxy.runpod.net:{EXTERNAL_PORT}.

However the blocked URL http://100.65.14.206:60892/openpose_editor_index/ wasn't the URL exposed by RunPod proxy, don't know how FastAPI made the IP/port. But certainly it's not truely using relative path.

Is it possible to ask FastAPI to use real relative path?

huchenlei commented 1 year ago

This seems like a similar issue to #26.

ak74fire commented 1 year ago

Sounds like same issue. I'm not familiar with FastAPI, but looks like it does handle proxy scenario: https://fastapi.tiangolo.com/advanced/behind-a-proxy/

huchenlei commented 1 year ago

Seems like I should prefix the path with /sdapi/v1 as all other paths in WebUI have this prefix.

huchenlei commented 1 year ago

Well. Things are pretty messy on WebUI's part. There are also prefix /internal other than sdapi/v1. You can try adding these prefixes to both this repo and controlnet repo to see if the problem is solved. I do not own a runpod instance so I cannot reproduce/test it.

Refs:

ak74fire commented 1 year ago

Adding the prefix doesn't solve the issue.

In browser console fetch('/sdapi/v1/openpose_editor_index') got a redirection (HTTP 307) to the non-https URL:

Cf-Cache-Status: DYNAMIC
Cf-Ray: 7da0b7f85abd0495-HKG
Content-Length: 0
Date: Tue, 20 Jun 2023 02:52:57 GMT
Location: http://100.65.10.194:60775/sdapi/v1/openpose_editor_index/
Nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=r2QumR4do3Hk3E8F2dOjE5iQNnccFN9CGKtHvMU6KswHyv4le3pfLIwAQRtZBLlrhEU%2BXf9h%2FssC4vjE8UX64yX0apdY0vVRGJ5C7P70rye8fk4h39PpOQT7l5PpWycNSeyV8lRzEDwtW%2Bb7UWOAGlKchnCMQw%3D%3D"}],"group":"cf-nel","max_age":604800}
Server: cloudflare
Strict-Transport-Security: max-age=63072000; includeSubDomains

RunPod doesn't seem to produce the redirection automatically as fetch('/info') got a normal HTTP 200 response.

Any idea where in the code issued the redirection?

ak74fire commented 1 year ago

The redirection could be caused by extra / at the end of the editor path:

https://github.com/huchenlei/sd-webui-openpose-editor/blob/8843a7e10c96a13f93b9f37ca16b3e39d8a4fcda/scripts/openpose_editor.py#L113

However in sd-webui-controlnet repo, the editor path has no ending /:

const EDITOR_PATH = '/openpose_editor_index';

I guess FastAPI would somehow issue a redirection in such situation.

Removed the extra / and now openpose editor UI can be loaded properly in RunPod.

Guess I'm too lazy to create a pull request, but it's only 2 lines of change:

index 21d7dd1..ba9b118 100644
--- a/scripts/openpose_editor.py
+++ b/scripts/openpose_editor.py
@@ -110,13 +110,13 @@ def mount_openpose_api(_: gr.Blocks, app: FastAPI):
         name="openpose_editor",
     )

-    @app.get("/openpose_editor_index/", response_class=HTMLResponse)
+    @app.get("/openpose_editor_index", response_class=HTMLResponse)
     async def index_get(request: Request):
         return templates.TemplateResponse(
             "index.html", {"request": request, "data": {}}
         )

-    @app.post("/openpose_editor_index/", response_class=HTMLResponse)
+    @app.post("/openpose_editor_index", response_class=HTMLResponse)
     async def index_post(request: Request, item: Item):
         return templates.TemplateResponse(
             "index.html", {"request": request, "data": item.dict()}

After all it has nothing to do with the path prefixes.

huchenlei commented 1 year ago

Fixed in https://github.com/huchenlei/sd-webui-openpose-editor/commit/84b1fe1059a2d6ea6474ee16742396f805f7ca53. Thanks for tracking this down!