Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: UnidentifiedImageError when using "Batch Process" in "Extras"
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Hello,

I'm trying to upscale a bunch of images in the "Extras" Tab. When I pick an image in the "Single Image" tab it works perfectly fine. But when I pick the exact same imagefile in the "Batch Process" and hit "Generate" I instantly get this error message in the UI:

UnidentifiedImageError: cannot identify image file <tempfile._TemporaryFileWrapper object at 0x000001F589DBF1F0>
Time taken: 0.00sTorch active/reserved: 1/2 MiB, Sys VRAM: 1277/4096 MiB (31.18%)

In the CMD it looks like this:
Error completing request
Arguments: (1, <PIL.Image.Image image mode=RGB size=960x1200 at 0x1F589DBF160>, [<tempfile._TemporaryFileWrapper object at 0x000001F589DBF1F0>], '', '', True, 0, 4, 512, 512, True, 'SwinIR_4x', 'None', 0, 0, 0, 0) {}
Traceback (most recent call last):
  File "C:\AI\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "C:\AI\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "C:\AI\stable-diffusion-webui\modules\postprocessing.py", line 21, in run_postprocessing
    image = Image.open(img)
  File "C:\AI\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 3283, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <tempfile._TemporaryFileWrapper object at 0x000001F589DBF1F0>




### Steps to reproduce the problem

1. Go to .... Extras, Batch Process
2. Press .... Import to add the image, and press Generate


### What should have happened?

It should create the upscaled image, just like in the Single Image tab.

### Commit where the problem happens

a0d07fb5

### What platforms do you use to access the UI ?

Windows

### What browsers do you use to access the UI ?

Google Chrome

### Command Line Arguments

```Shell
git pull
pause 

 --xformers --medvram
```


### List of extensions

no

### Console logs

```Shell
C:\AI\stable-diffusion-webui>git pull
Already up to date.

C:\AI\stable-diffusion-webui>pause
Drücken Sie eine beliebige Taste . . .
venv "C:\AI\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
Commit hash: a0d07fb5807ad55c8ccfdfc9a6d9ae3c62b9d211
Installing requirements for Web UI
Launching Web UI with arguments: --xformers --medvram
Loading weights [cc6cb27103] from C:\AI\stable-diffusion-webui\models\Stable-diffusion\model.ckpt
Creating model from config: C:\AI\stable-diffusion-webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 3.2s (load weights from disk: 1.6s, create model: 0.5s, apply weights to model: 0.5s, apply half(): 0.6s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 12.3s (import torch: 2.7s, import gradio: 1.5s, import ldm: 0.4s, other imports: 1.3s, setup codeformer: 0.1s, load scripts: 2.2s, load SD checkpoint: 3.5s, create ui: 0.3s, gradio launch: 0.1s).
Error completing request
Arguments: (1, None, [<tempfile._TemporaryFileWrapper object at 0x000001E5841F11E0>], '', '', True, 0, 4, 512, 512, True, 'None', 'None', 0, 0, 0, 0) {}
Traceback (most recent call last):
  File "C:\AI\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "C:\AI\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "C:\AI\stable-diffusion-webui\modules\postprocessing.py", line 21, in run_postprocessing
    image = Image.open(img)
  File "C:\AI\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 3283, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <tempfile._TemporaryFileWrapper object at 0x000001E5841F11E0>
```


### Additional information

_No response_


Discussion:
I just got the exact same error when trying to upscale images
> I just got the exact same error when trying to upscale images

yes. I got the same, when trying to inpaint for only masked
I am also having this issue, I did notice if I load images from the directory then it works fine
Same here :-( Is there any update onm this issue yet?
AFAIK this problem happens on https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/8ea8e712c43e493a9c96dcec7dfbc036a8630c97 and after, but not on https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/6a04a7f20fcc4a992ae017b06723e9ceffe17b37.
> AFAIK this problem happens on [8ea8e71](https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/8ea8e712c43e493a9c96dcec7dfbc036a8630c97) and after, but not on [6a04a7f](https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/6a04a7f20fcc4a992ae017b06723e9ceffe17b37).

Thank you!! Very helpful
So will this be fixed in the next update?
#9400 same problem when i use scripts 'multi-frame-video-rendering', notice me pls if anyone know how to fix this issue.
> #9400 same problem when i use scripts 'multi-frame-video-rendering', notice me pls if anyone know how to fix this issue.

line28 of its .py file
 change to 
file_count = "directory" 
from ="multiple"

Resolving patch:
diff --git a/modules/postprocessing.py b/modules/postprocessing.py
--- a/modules/postprocessing.py
+++ b/modules/postprocessing.py
@@ -1,4 +1,6 @@
 import os
+import tempfile
+from typing import List
 
 from PIL import Image
 
@@ -6,7 +8,7 @@
 from modules.shared import opts
 
 
-def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir, show_extras_results, *args, save_output: bool = True):
+def run_postprocessing(extras_mode, image, image_folder: List[tempfile.NamedTemporaryFile], input_dir, output_dir, show_extras_results, *args, save_output: bool = True):
     devices.torch_gc()
 
     shared.state.begin()
@@ -22,7 +24,7 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
                 image = img
                 fn = ''
             else:
-                image = Image.open(img)
+                image = Image.open(os.path.abspath(img.name))
                 fn = os.path.splitext(img.orig_name)[0]
 
             image_data.append(image)
diff --git a/modules/ui_postprocessing.py b/modules/ui_postprocessing.py
--- a/modules/ui_postprocessing.py
+++ b/modules/ui_postprocessing.py
@@ -13,7 +13,7 @@ def create_ui():
                     extras_image = gr.Image(label="Source", source="upload", interactive=True, type="pil", elem_id="extras_image")
 
                 with gr.TabItem('Batch Process', elem_id="extras_batch_process_tab") as tab_batch:
-                    image_batch = gr.File(label="Batch Process", file_count="multiple", interactive=True, type="file", elem_id="extras_image_batch")
+                    image_batch = gr.Files(label="Batch Process", interactive=True, elem_id="extras_image_batch")
 
                 with gr.TabItem('Batch from Directory', elem_id="extras_batch_directory_tab") as tab_batch_dir:
                     extras_batch_input_dir = gr.Textbox(label="Input directory", **shared.hide_dirs, placeholder="A directory on the same machine where the server is running.", elem_id="extras_batch_input_dir")


Test patch: