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]: UnboundLocalError: local variable 'author' referenced before assignment #234

Closed RedFoxNightfox closed 4 months ago

RedFoxNightfox commented 4 months ago

Describe the bug.

UnboundLocalError: local variable 'author' referenced before assignment

Steps to reproduce the problem.

  1. Go to Browser
  2. Search for model
  3. Press desired model
  4. Sometimes get error

Expected behavior

get model info for download

System info

Console logs

Traceback (most recent call last):
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 451, in update_models_dropdown
    (html, tags, base_mdl, DwnButton, SaveImages, DelButton, filelist, filename, dl_url, id, current_sha256, install_path, sub_folder) = _api.update_model_info(model_string, model_versions.get('value'))
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 935, in update_model_info
    "Author name": author,
UnboundLocalError: local variable 'author' referenced before assignment
Traceback (most recent call last):
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 451, in update_models_dropdown
    (html, tags, base_mdl, DwnButton, SaveImages, DelButton, filelist, filename, dl_url, id, current_sha256, install_path, sub_folder) = _api.update_model_info(model_string, model_versions.get('value'))
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 935, in update_model_info
    "Author name": author,
UnboundLocalError: local variable 'author' referenced before assignment

Additional information

Prolly the same type of problem as #223, with a different variable

BlafKing commented 4 months ago

Thanks for reporting!

I can't on first glance exactly figure out why this is happening, could you provide me with an example model that this occurs on?

RedFoxNightfox commented 4 months ago

I can't provide a link, as the item in question actually doesn't exist on civitai, while still showing up in the extension.

the API seems to not be removing dead links from the search in the extension, while removing them from search on the site.

BlafKing commented 4 months ago

I see then that's probably what was causing the issue.

Could there be any other way that you could provide a way to find one of these models? Would help me to find a way to perhaps detect if a model is no longer available on CivitAI and hide it automatically.

RedFoxNightfox commented 4 months ago

sure, If you search "atk" there is one model that does not actually exist shown, "atk style hairy" or searching "realcartoon" there is "bimbo realcartoon3d" that has the same error

RedFoxNightfox commented 4 months ago

there is another error related to this:

clicking the model dropdown menu when searching "realcartoon" and selecting "realcartoon(351650)" causes this error:

Traceback (most recent call last):
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "M:\Stable-Diffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_gui.py", line 451, in update_models_dropdown
    (html, tags, base_mdl, DwnButton, SaveImages, DelButton, filelist, filename, dl_url, id, current_sha256, install_path, sub_folder) = _api.update_model_info(model_string, model_versions.get('value'))
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 833, in update_model_info
    for root, dirs, files in os.walk(model_folder, followlinks=True):
UnboundLocalError: local variable 'model_folder' referenced before assignment
BlafKing commented 4 months ago

I've posted another hotfix which should fix both the issue you posted here.

I couldn't find a definitive way to tell if a model has been removed from CivitAI in the first example, so I've made it possible to select the model, but the download button will not work and notify you that the model no longer exists on CivitAI when pressed.

The other error was caused by models having no versions but still showing up in the dropdown, I've now added an extra step to also filter out models without any versions from there as well!

Thanks again for the quick replies and bug report, I'll mark this as resolved 👍🏻