yfszzx / stable-diffusion-webui-inspiration

115 stars 23 forks source link

ValueError: invalid literal for int() with base 10: 'NaN' #34

Closed jsmile closed 1 year ago

jsmile commented 1 year ago

I clicked a left image of inspiration tab page in Stable Diffusion WebUI, right of the page show Error button. And cmd console said like below,

Traceback (most recent call last): File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 394, in run_predict output = await app.get_blocks().process_api( File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1075, in process_api result = await self.call_function( File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 884, in call_function prediction = await anyio.to_thread.run_sync( File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "F:\AI\WebUI\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, *args) File "F:\AI\WebUI\stable-diffusion-webui\extensions\stable-diffusion-webui-inspiration\scripts\inspiration.py", line 158, in select_click name = name_list[int(index)] ValueError: invalid literal for int() with base 10: 'NaN'

How can I fix it ?

vintol commented 1 year ago

Alright, So this is due to the

stable-diffusion-webui-inspiration\scripts\inspiration.py : 146

def select_click(index, name_list):
    name = name_list[int(index)]
    path = os.path.join(inspiration_dir, name)
    images = os.listdir(path)
    return name, [os.path.join(path, x) for x in images], ""

The index is expected to be a whole no in string format, which it is then converted into integer to slice the list of inspirations being displayed. Which will then display the corresponding images from that artist in bottom right.

The problem is now, after some updates The value of index passed is NaN, no matter which tile you click on. Which while converted into integer, throws an exception.

This function is called here .

stable-diffusion-webui-inspiration\scripts\inspiration.py : 250

select_button.click(select_click, _js="inspiration_selected", inputs=[name, name_list], outputs=[name, style_gallery, warning])

In the HTML, I found just one html button with ID inspiration_select_button, it had index NaN. This is significant because of inspiration_selected function.

stable-diffusion-webui-inspiration/javascript/inspiration.js : 18

function inspiration_selected(name, name_list){
    var btn = gradioApp().getElementById("inspiration_select_button")
    return [gradioApp().getElementById("inspiration_select_button").getAttribute("img-index")];
}  

Rabbit hole, goes deeper >>>

This is not setting the img-index right

var inspiration_image_click = function(){
    var index =  public_image_index_in_gallery(this, gradioApp().getElementById("inspiration_gallery"));
    var btn = gradioApp().getElementById("inspiration_select_button");
    btn.setAttribute("img-index", index);
    setTimeout(function(btn){btn.click();}, 10, btn);
}
vintol commented 1 year ago

Done.

I have submitted a pull request.

Here's the fix.

[stable-diffusion-webui-inspiration]/javascript/inspiration.js :: 

Change Line No 2 

From  : 
    var imgs = gallery.querySelectorAll("img.h-full")   

To This :
    var imgs = gallery.querySelectorAll("img")   
remark3d commented 1 year ago

Everything works perfectly now, thank you very much! :-)

jsmile commented 1 year ago

Thanks you help me.

jsmile commented 1 year ago

So, do I reinstall 'inspiration' extension ? Or Is it necessary I fix inspiration.js ?

But I tried to fix inspiration.js and saved it. From : var imgs = gallery.querySelectorAll("img.h-full")
To This : var imgs = gallery.querySelectorAll("img")

The situation is the almost same.

inspiration ui says red color 'error' message again.

cmd says :

Traceback (most recent call last): File "F:\AI\Vlad1111\automatic\venv\lib\site-packages\gradio\routes.py", line 399, in run_predict output = await app.get_blocks().process_api( File "F:\AI\Vlad1111\automatic\venv\lib\site-packages\gradio\blocks.py", line 1297, in process_api inputs = self.preprocess_data(fn_index, inputs, state) File "F:\AI\Vlad1111\automatic\venv\lib\site-packages\gradio\blocks.py", line 1133, in preprocess_data self.validate_inputs(fn_index, inputs) File "F:\AI\Vlad1111\automatic\venv\lib\site-packages\gradio\blocks.py", line 1120, in validate_inputs raise ValueError( ValueError: An event handler (select_click) didn't receive enough input values (needed: 2, got: 1). Check if the event handler calls a Javascript function, and make sure its return value is correct. Wanted inputs: [textbox, state] Received inputs: ["1"]

What should I do ?