mattyamonaca / PBRemTools

Precise background remover
MIT License
348 stars 28 forks source link

Getting a unexpected keyword argument 'format' error #42

Open Aamir3d opened 1 year ago

Aamir3d commented 1 year ago

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).

skyheros001 commented 1 year ago

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

skyheros001 commented 1 year ago

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.

Hilurex commented 1 year ago

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

kotaro5487 commented 1 year ago

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

GoldenLoong commented 1 year ago

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

bluce commented 1 year ago

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

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