zixaphir / Stable-Diffusion-Webui-Civitai-Helper

Stable Diffusion Webui Extension for Civitai, to manage your model much more easily.
175 stars 24 forks source link

process_sd15_info assumes basemodel is at least 4 characters long, however, "SVD" is only three characters long, stopping the script #113

Open brendanhoar opened 1 week ago

brendanhoar commented 1 week ago

Have you read document?

Yes

Have you checked console log window's msg?

Yes

Describe Issue

process_sd15_info assumes basemodel is at least 4 characters long, however, "SVD" is only three characters long, stopping the script.

As a fix would be extremely simple, normally I would have submitted a PR...but as there are several ways to fix this, and likely only one of which you'd prefer...and also the comments above this section probably need your review anyway...I figured an issue was better.

Console log's msg or screenshot for function issue

... CHv1.8.7: Creating model info for: dragnuwaSvd_v10.safetensors CHv1.8.7: model action sha256: 2e731d4a9fcf5ece7843b0458885ea7b484786c0f0167fda4ea1c2bc14d50eac CHv1.8.7: Request model info from civitai CHv1.8.7: Fetching Parent Model Information CHv1.8.7: Request model info from civitai: 275063 Traceback (most recent call last): File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict output = await app.get_blocks().process_api( File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api result = await self.call_function( File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\blocks.py", line 1117, in call_function prediction = await utils.async_iteration(iterator) File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\utils.py", line 350, in async_iteration return await iterator.__anext__() File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\utils.py", line 343, in __anext__ return await anyio.to_thread.run_sync( File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread return await future File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run result = context.run(func, *args) File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\utils.py", line 326, in run_sync_iterator_async return next(iterator) File "G:\___all_webuis\sd-webui-dev-civitai-maint\venv\lib\site-packages\gradio\utils.py", line 695, in gen_wrapper yield from f(*args, **kwargs) File "G:\___all_webuis\sd-webui-dev-civitai-maint\extensions\Stable-Diffusion-Webui-Civitai-Helper\ch_lib\model_action_civitai.py", line 163, in scan_model for result in scan_single_model(filepath, model_type, refetch_old, delay): File "G:\___all_webuis\sd-webui-dev-civitai-maint\extensions\Stable-Diffusion-Webui-Civitai-Helper\ch_lib\model_action_civitai.py", line 96, in scan_single_model model.process_model_info(filepath, model_info, model_type, refetch_old=refetch_old) File "G:\___all_webuis\sd-webui-dev-civitai-maint\extensions\Stable-Diffusion-Webui-Civitai-Helper\ch_lib\model.py", line 352, in process_model_info process_sd15_info(sd15_file, model_info, parent, model_type, refetch_old) File "G:\___all_webuis\sd-webui-dev-civitai-maint\extensions\Stable-Diffusion-Webui-Civitai-Helper\ch_lib\model.py", line 384, in process_sd15_info version = base_model[3] IndexError: string index out of range

zixaphir commented 6 days ago

I'm open to alternative solutions to this since the current solution is too prone to breakage. It was a neat trick when there were only a few models, but now keeping up with the different variants is too much for a dictionary and it was never forward thinking.

brendanhoar commented 6 days ago

My recommendation would be to try something different?

The C# code for SwarmUI (ex-StableSwarm) has a class that mostly looks at existences of tensor names in the files as a backup to using the (assumed to be correct) metadata.

It's not perfect (I'm putting together some notes on a handful confounding models, hoping to find some tweaks to recommend), but it's pretty good.

https://github.com/mcmonkeyprojects/SwarmUI/blob/master/src/Text2Image/T2IModelClassSorter.cs

Granted that's 100% not dependent on what comes from civitai (but it's likely to be more correct). Which...might be outside the scope of what you want to do here.

B

zixaphir commented 6 days ago

Honestly, I wish it were as easy as just using a canonical name, but the deeper issue is that this metadata isn't really meant to be extensible. On the SD WebUI side, the only options are "SD1", "SD2", "SDXL", or "Unknown", and are defined at the model implementation level (such as in extensions-builtin/Lora/ui_edit_user_metadata.py). Honestly, I'm probably just going to do a little regex and pattern match to these values.

brendanhoar commented 6 days ago

Fair enough, reasonable.

In the short term I monkeypatched by enclosing that section in a try.