mattyamonaca/PBRemTools

Getting a unexpected keyword argument 'format' error

Opened this issue · 6 comments

Running on Automatic1111

Traceback (most recent call last):
  File "O:\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "O:\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1326, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "O:\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1260, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "O:\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\components.py", line 4457, in postprocess
    file = self.img_array_to_temp_file(img, dir=self.DEFAULT_TEMP_DIR)
  File "O:\Automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\components.py", line 355, in img_array_to_temp_file
    return self.pil_to_temp_file(pil_image, dir, format="png")
TypeError: save_pil_to_file() got an unexpected keyword argument 'format'

This error appears when an image is uploaded or dragged (it doesn't matter if the image is JPG or PNG).

me too, cant find case, the error that only occurred after today's upgrade will now be found in any image

I have looked at the error message and tried to solve it. The reason seems to be due to compatibility issues with gradio version. My guess is that our version is too high. Of course, this is just my assumption.

A temporary solution is to find the file gradio\components.py in venv\Lib\site-packages\gradio\components.py, around line 355. There are two functions, pil_to_temp_file and img_array_to_temp_file. I changed the code of these two functions as follows:

def pil_to_temp_file(self, img: _Image.Image, dir: str) -> str:
bytes_data = processing_utils.encode_pil_to_bytes(img, "png")
temp_dir = Path(dir) / self.hash_bytes(bytes_data)
temp_dir.mkdir(exist_ok=True, parents=True)
filename = str(temp_dir / f"image.png")
img.save(filename, pnginfo=processing_utils.get_pil_metadata(img))
return filename

def img_array_to_temp_file(self, arr: np.ndarray, dir: str) -> str:
pil_image = _Image.fromarray(
processing_utils._convert(arr, np.uint8, force_copy=False)
)
return self.pil_to_temp_file(pil_image, dir)

I deleted the variable format in these two functions and finally solved the problem. I hope the author will consider this compatibility issue.

I also have the same error, i hope they can fix it

opparco/stable-diffusion-webui-two-shot#54
I believe this link is referring to a similar error. I hope it gets resolved soon.

我也是,不过把stabel diffusion更新到最新的2023.06.27版本后,这个问题就消失了。

bluce commented

Modify file
modules\ui_tempdir.py line 34
add param: format="png"

def save_pil_to_file(self, pil_image, dir=None, format="png"):