Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a unexpected keyword argument 'format' error #42

Open
Aamir3d opened this issue Jun 5, 2023 · 6 comments
Open

Getting a unexpected keyword argument 'format' error #42

Aamir3d opened this issue Jun 5, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Aamir3d
Copy link

Aamir3d commented Jun 5, 2023

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

@mattyamonaca mattyamonaca added the bug Something isn't working label Jun 6, 2023
@skyheros001
Copy link

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

@skyheros001
Copy link

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
Copy link

Hilurex commented Jun 12, 2023

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

@kotaro5487
Copy link

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

kotaro5487 referenced this issue in AUTOMATIC1111/stable-diffusion-webui Jun 14, 2023
@GoldenLoong
Copy link

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

@bluce
Copy link

bluce commented Jul 3, 2023

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants