BlafKing / sd-civitai-browser-plus

Extension to access CivitAI via WebUI: download, delete, scan for updates, list installed models, assign tags, and boost downloads with multi-threading.
GNU Affero General Public License v3.0
289 stars 44 forks source link

[Bug]: Browser won't load in Automatic1111 after reinstall #250

Closed FilkerZero closed 4 months ago

FilkerZero commented 4 months ago

Describe the bug.

After reinstalling, the extension does not work

Steps to reproduce the problem.

  1. I went to the extensions tag and scanned for updates, then applied and restarted the web UI.
  2. I got GIT errors and the WebUI did not restart.
  3. I killed the server and closed the browser window.
  4. I started Automatic1111, saw some errors about the browser, and the tab for it did not appear in the webui.
  5. I went to the extensions tab, disabled sd-civitai-browser-plus
  6. I clicked on the Apply and restart UI button
  7. I killed the server and closed the webui browser tab
  8. I deleted the extension folder from Automatic1111/stable-diffusion-webui/extensions
  9. I started Automatic1111
  10. I went to the extensions tab in the webui and installed the browser from the Available sub-tab
  11. I went back to the Installed tab and clicked on the Apply and restart UI button
  12. The Webui restarted, I saw errors in the console relating to webui, and the browser tab did not show in the Webui
  13. I killed the server and closed the webui browser tab
  14. I restarted Automatic1111, when the UI came up, I got the following errors in the console: and no browser tab shows up in the WebUI
    
    *** Error loading script: civitai_api.py
    Traceback (most recent call last):
      File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 19, in <module>
        from scripts.civitai_global import print, debug_print
    ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)

*** Error loading script: civitai_download.py Traceback (most recent call last): File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module module_spec.loader.exec_module(module) File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_download.py", line 15, in from scripts.civitai_global import print, debug_print ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)


*** Error loading script: civitai_file_manage.py Traceback (most recent call last): File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module module_spec.loader.exec_module(module) File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_file_manage.py", line 20, in import scripts.civitai_api as _api File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 19, in from scripts.civitai_global import print, debug_print ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)


*** Error loading script: civitai_gui.py Traceback (most recent call last): File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module module_spec.loader.exec_module(module) File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 10, in from scripts.civitai_global import print, debug_print ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)


### Expected behavior

When I start the webui from Automatic1111, that the "CivitAI Browser+" tab shows up and is functional.

### System info

{
  "date": "Tue Mar 26 20:51:31 2024",
  "timestamp": "20:51:55",
  "uptime": "Tue Mar 26 20:29:34 2024",
  "version": {
    "app": "stable-diffusion-webui.git",
    "updated": "2024-03-02",
    "hash": "bef51aed",
    "url": "https://github.com/AUTOMATIC1111/stable-diffusion-webui.git/tree/master"
  },
  "torch": "2.1.2+cu121 autocast  half",
  "gpu": {
    "device": "NVIDIA GeForce RTX 3060 (1) (sm_90) (8, 6)",
    "cuda": "12.1",
    "cudnn": 8801,
    "driver": "546.33"
  },
  "state": {
    "started": "Tue Mar 26 20:51:55 2024",
    "step": "0 / 0",
    "jobs": "0 / 0",
    "flags": "",
    "job": "",
    "text-info": ""
  },
  "memory": {
    "ram": {
      "free": 30.07,
      "used": 1.79,
      "total": 31.86
    },
    "gpu": {
      "free": 8.17,
      "used": 3.83,
      "total": 12
    },
    "gpu-active": {
      "current": 2.06,
      "peak": 5.15
    },
    "gpu-allocated": {
      "current": 2.06,
      "peak": 5.15
    },
    "gpu-reserved": {
      "current": 2.52,
      "peak": 5.42
    },
    "gpu-inactive": {
      "current": 0.45,
      "peak": 0.58
    },
    "events": {
      "retries": 0,
      "oom": 0
    },
    "utilization": 0
  },
  "optimizations": [
    "none"
  ],
  "libs": {
    "xformers": "0.0.23.post1",
    "diffusers": "0.27.0",
    "transformers": "4.30.2"
  },
  "repos": {
    "Stable Diffusion": "[cf1d67a] 2023-03-25",
    "Stable Diffusion XL": "[45c443b] 2023-07-26",
    "BLIP": "[48211a1] 2022-06-07",
    "k_diffusion": "[ab527a9] 2023-08-12"
  },
  "device": {
    "active": "cuda",
    "dtype": "torch.float16",
    "vae": "torch.float16",
    "unet": "torch.float16"
  },
  "model": {
    "configured": {
      "base": "marshmallowmixNSFW_v10.safetensors [6858c404d8]",
      "refiner": "",
      "vae": "kl-f8-anime2.ckpt"
    },
    "loaded": {
      "base": "D:\\Automatic1111\\stable-diffusion-webui\\models\\Stable-diffusion\\marshmallowmixNSFW_v10.safetensors",
      "refiner": "",
      "vae": null
    }
  },
  "schedulers": [
    "DDIM",
    "DPM adaptive",
    "DPM fast",
    "DPM++ 2M",
    "DPM++ 2M Karras",
    "DPM++ 2M SDE",
    "DPM++ 2M SDE Exponential",
    "DPM++ 2M SDE Heun",
    "DPM++ 2M SDE Heun Exponential",
    "DPM++ 2M SDE Heun Karras",
    "DPM++ 2M SDE Karras",
    "DPM++ 2S a",
    "DPM++ 2S a Karras",
    "DPM++ 3M SDE",
    "DPM++ 3M SDE Exponential",
    "DPM++ 3M SDE Karras",
    "DPM++ SDE",
    "DPM++ SDE Karras",
    "DPM2",
    "DPM2 Karras",
    "DPM2 a",
    "DPM2 a Karras",
    "Euler",
    "Euler a",
    "Heun",
    "LCM",
    "LMS",
    "LMS Karras",
    "PLMS",
    "Restart",
    "UniPC"
  ],
  "extensions": [
    "--sd-webui-ar-plus (enabled)",
    "ABG_extension (enabled)",
    "Config-Presets (enabled)",
    "DreamArtist-sd-webui-extension (enabled)",
    "LDSR (enabled builtin)",
    "Lora (enabled builtin)",
    "SD-latent-mirroring (enabled)",
    "ScuNET (enabled builtin)",
    "Stylez (enabled)",
    "SwinIR (enabled builtin)",
    "a1111-sd-webui-tagcomplete (enabled)",
    "adetailer (enabled)",
    "canvas-zoom-and-pan (enabled builtin)",
    "clip-interrogator-ext (enabled)",
    "extra-options-section (enabled builtin)",
    "hypertile (enabled builtin)",
    "mobile (enabled builtin)",
    "model-keyword (enabled)",
    "multi-subject-render (enabled)",
    "prompt-bracket-checker (enabled builtin)",
    "sd-3dmodel-loader (enabled)",
    "sd-civitai-browser-plus (enabled)",
    "sd-dynamic-prompts (enabled)",
    "sd-extension-system-info (enabled)",
    "sd-ratio-lock (enabled)",
    "sd-webui-3d-open-pose-editor (enabled)",
    "sd-webui-agentattention (enabled)",
    "sd-webui-api-payload-display (enabled)",
    "sd-webui-ar (enabled)",
    "sd-webui-aspect-ratio-helper (disabled)",
    "sd-webui-cads (enabled)",
    "sd-webui-civbrowser (disabled)",
    "sd-webui-controlnet (enabled)",
    "sd-webui-custom-autolaunch (enabled)",
    "sd-webui-deepdanbooru-object-recognition (enabled)",
    "sd-webui-inpaint-anything (enabled)",
    "sd-webui-inpaint-background (enabled)",
    "sd-webui-latent-regional-helper (enabled)",
    "sd-webui-llul (enabled)",
    "sd-webui-negpip (enabled)",
    "sd-webui-prompt-history (enabled)",
    "sd-webui-reactor (enabled)",
    "sd-webui-regional-prompter (enabled)",
    "sd-webui-replacer (enabled)",
    "sd-webui-roop (disabled)",
    "sd-webui-sc-loader (enabled)",
    "sd-webui-segment-anything (enabled)",
    "soft-inpainting (enabled builtin)",
    "stable-diffusion-webui-composable-lora (enabled)",
    "stable-diffusion-webui-dataset-tag-editor (enabled)",
    "stable-diffusion-webui-depthmap-script (enabled)",
    "stable-diffusion-webui-images-browser (enabled)",
    "stable-diffusion-webui-model-toolkit (enabled)",
    "stable-diffusion-webui-rembg (enabled)",
    "stable-diffusion-webui-text2prompt (enabled)",
    "stable-diffusion-webui-tokenizer (enabled)",
    "stable-diffusion-webui-two-shot (enabled)",
    "uddetailer (disabled)"
  ],
  "platform": {
    "arch": "AMD64",
    "cpu": "Intel64 Family 6 Model 151 Stepping 2, GenuineIntel",
    "system": "Windows",
    "release": "Windows-10-10.0.22631-SP0",
    "python": "3.10.6"
  },
  "crossattention": "Automatic",
  "backend": "",
  "pipeline": ""
}

### Console logs

```Shell
venv "D:\Automatic1111\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.8.0
Commit hash: bef51aed032c0aaa5cfd80445bc4cf0d85b408b5
CUDA 12.1
Launching Web UI with arguments: --theme dark --xformers --api --gradio-img2img-tool color-sketch --cors-allow-origins http://localhost:5173
Issue in parsing YAML file ._cameras.yaml: 'utf-8' codec can't decode byte 0xe2 in position 37: invalid continuation byte
[-] ADetailer initialized. version: 24.3.3, num models: 16
*** Error loading script: civitai_api.py
    Traceback (most recent call last):
      File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 19, in <module>
        from scripts.civitai_global import print, debug_print
    ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)

---
*** Error loading script: civitai_download.py
    Traceback (most recent call last):
      File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_download.py", line 15, in <module>
        from scripts.civitai_global import print, debug_print
    ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)

---
*** Error loading script: civitai_file_manage.py
    Traceback (most recent call last):
      File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_file_manage.py", line 20, in <module>
        import scripts.civitai_api as _api
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 19, in <module>
        from scripts.civitai_global import print, debug_print
    ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)

---
*** Error loading script: civitai_gui.py
    Traceback (most recent call last):
      File "D:\Automatic1111\stable-diffusion-webui\modules\scripts.py", line 527, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "D:\Automatic1111\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 10, in <module>
        from scripts.civitai_global import print, debug_print
    ImportError: cannot import name 'debug_print' from 'scripts.civitai_global' (D:\Automatic1111\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_global.py)

---
ControlNet preprocessor location: D:\Automatic1111\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator\downloads
2024-03-26 20:29:44,648 - ControlNet - INFO - ControlNet v1.1.441
2024-03-26 20:29:44,742 - ControlNet - INFO - ControlNet v1.1.441
20:29:46 - ReActor - STATUS - Running v0.7.0-b7 on Device: CUDA
Started the depthmap API. DO NOT HOST PUBLICLY - SECURITY RISKS!
[text2prompt] Following databases are available:
    all-mpnet-base-v2 : danbooru_strict
Loading weights [6858c404d8] from D:\Automatic1111\stable-diffusion-webui\models\Stable-diffusion\marshmallowmixNSFW_v10.safetensors
Creating model from config: D:\Automatic1111\stable-diffusion-webui\configs\v1-inference.yaml
2024-03-26 20:29:50,119 - ControlNet - INFO - ControlNet UI callback registered.
Couldn't find VAE named kl-f8-anime2.ckpt; using None instead
Applying attention optimization: xformers... done.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
[text2prompt] Loading database with name "all-mpnet-base-v2 : danbooru_strict"...
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
[text2prompt] Database loaded
No Image data blocks found.
No Image data blocks found.
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
Startup time: 45.2s (prepare environment: 10.7s, import torch: 3.8s, import gradio: 0.9s, setup paths: 0.9s, initialize shared: 0.2s, other imports: 0.5s, list extensions: 0.1s, list SD models: 0.3s, load scripts: 12.8s, scripts before_ui_callback: 0.1s, create ui: 12.8s, gradio launch: 0.6s, add APIs: 1.4s).
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
No Image data blocks found.
Model loaded in 16.7s (create model: 0.3s, apply weights to model: 2.7s, load textual inversion embeddings: 13.3s, calculate empty prompt: 0.1s).

Additional information

When I did the check for updates in the extensions tab, the sd-civitai-browser-plus extension said something like behind HEAD before I hit the Apply and restart UI button.

irldoggo commented 4 months ago

I can confirm with forge as well, after update the extension no longer loads at all.

kyle215ps3 commented 4 months ago

Same here on forge.

Yomisana commented 4 months ago

same bug here too on a1111-webui

Number6UK commented 4 months ago

Hi all, I'm not a big participant on github or particularly familiar with Python, but I think I can see where the problem is coming from. My apologies in advance if the following is all glaringly obvious to everyone already:

Three scripts are trying to import and/or use the debug_print function, which they're expecting to find in scripts/civitai_global.py.

The three scripts in question are:

https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_api.py#L19

https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_api.py#L219

https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_api.py#L290

https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_api.py#L328


https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_gui.py#L10


https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_download.py#L15


In each case, they're trying to import the function from the scripts/civitai_global.py file however that script doesn't expose debug_print in the global statement: https://github.com/BlafKing/sd-civitai-browser-plus/blob/b39a2c2128ce5ce74d7231b1ee42e89b2e220082/scripts/civitai_global.py#L6

Nor does it define it as a debug_print function as it does for print towards the bottom of the file:

_print = print
def print(print_message):
    _print(f'\033[96mCivitAI Browser+\033[0m: {print_message}')

I'm just guessing here but I'd imagine from looking at the code that we could probably get local copies working temporarily by either editing out the references to and uses of debug_print in those files, or defining a debug_print function (it could even be one that doesn't do anything, though I don't know how Python deals with optional parameters and that sort of syntax) - probably just duplicating the print definintion and function and renaming the duplicated copy so you end up with the bottom of the script looking like this:

_print = print
def print(print_message):
    _print(f'\033[96mCivitAI Browser+\033[0m: {print_message}')

_debug_print = debug_print
def debug_print(print_message):
    _print(f'\033[96mCivitAI Browser+ DEBUGGING MESSAGE\033[0m: {print_message}')

in civitai_global.py and adding , debug_print (note the comma) after the word "print"at the end of the global statement on line 6 would, I think make it work.

PLease note I haven't tried this out, so if you do want to try it locally, I'd suggest being cautious but as far as I can see there won't be any harm in doing so (other than your local version won't match the main repo and might complain if you try to git pull, but in any case once it's fixed properly at source you could simply delete your local version and install it again as normal.)

philmcrakin commented 4 months ago

EDIT: SEE THE POST BELOW ### THIS!

Until the developer creates the debug_print function, you can apply this temporary fix.

In the stable-diffusion>extensions>sd-civitai-browser-plus>scripts directory (or the equivalent location for your system), update the following 3 files:

  1. In file: civitai_api.py

    • On line 19, change:
    • from scripts.civitai_global import print, debug_print To:
    • from scripts.civitai_global import print
  2. In file:civitai_download.py

    • On line 15, change
    • from scripts.civitai_global import print, debug_print To:
    • from scripts.civitai_global import print
  3. In file: civitai_gui.py

    • On line 10, change
    • from scripts.civitai_global import print, debug_print To:
    • from scripts.civitai_global import print

This temporary fix should allow you to use the extension until the developer implements the debug_print function.

All you're doing is removing , debug_print from the end of those lines listed above.

--Tested with Stable Diffusion WebUI Forge-- --Tested with Automatic1111 webui--

philmcrakin commented 4 months ago

Actually a better way is to just edit civitai_global.pyinstead, At the bottom of that file add this: def debug_print(print_message): _print(f'\033[96mCivitAI Browser+ DEBUG\033[0m: {print_message}')

echdareez commented 4 months ago

Can confirm : @philmcrakin 's solution works splendidly 👍

lmgj21 commented 4 months ago

@philmcrakin This does work, but I've noticed that it will not show multiple versions. At least not for me.

BlafKing commented 4 months ago

Thanks for reporting!

The fix @philmcrakin posted was intended to be included in the update, looks like I forgot to include it 😅 Published another commit which contains this code by default.

I'll mark this as resolved 👍🏻