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
309 stars 53 forks source link

[Bug]: UnboundLocalError: local variable 'current_image' referenced before assignment #223

Closed RedFoxNightfox closed 7 months ago

RedFoxNightfox commented 7 months ago

Describe the bug.

UnboundLocalError: local variable 'current_image' referenced before assignment

Steps to reproduce the problem.

  1. Go to update models
  2. Press "Save HTML file for each model when updating info & tags (increases process time)."
  3. Press "Update model info & tags"
  4. Error occurs with finalization process

Expected behavior

Expected behavior is for there to not be an error.

System info

Console logs

CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\SDXL 1.0\sdxlVAE_sdxlVAE.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\SDXL 1.0\xlVAEC_f1.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\anythingKlF8Anime2VaeFtMse840000_klF8Anime2.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\chilloutmix_NiPrunedFp32Fix.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\clearvae_v23.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\color101VAE_v1.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\customvae_q6.json"
CivitAI Browser+: Model info saved to "M:\Stable-Diffusion\stable-diffusion-webui\models\VAE\customvae_v20.json"
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_file_manage.py", line 1024, in file_scan
    preview_html = _api.update_model_info(None, model_versions.get('value'), True, id_value, api_response, True)
  File "M:\Stable-Diffusion\stable-diffusion-webui\extensions\sd-civitai-browser-plus\scripts\civitai_api.py", line 799, in update_model_info
    prompt_dict = current_image['meta']
UnboundLocalError: local variable 'current_image' referenced before assignment

Additional information

No response

RedFoxNightfox commented 7 months ago

I ran the code through an AI along with the error message, and it says the following:

The error UnboundLocalError: local variable 'current_image' referenced before assignment occurs because the variable current_image is referenced before it's assigned a value within the loop. This happens when the loop for item in model_images['items'] doesn't find a matching pic['id'], hence current_image is not assigned within that loop, but it's being referenced later.

To fix this error, you can initialize current_image outside of the loop and set it to None initially. Then, inside the loop, if a matching pic['id'] is found, you can update current_image.

so it seems the error is occuring when the extention does not find a pic['id'] value.

BlafKing commented 7 months ago

Thanks for reporting! I'll make sure to post a fix for this shortly, it looks like there is a better way of fetching the prompt info for images rather than using the current images endpoint, so I'll implement that in a bit! :)

BlafKing commented 7 months ago

Should now be fixed in the latest commit! :)

I'll mark this as resolved 👍🏻