diff options
author | Neil Mahseth <neilmahaseth@gmail.com> | 2023-07-06 16:32:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 16:32:47 +0000 |
commit | c258dd34a888b7c6c9e4c9bbef76732d9d7db6e7 (patch) | |
tree | 80b4c8e9e4f3c7a62ae592a14621848b79a7c9a3 /modules/ui.py | |
parent | 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8 (diff) | |
download | stable-diffusion-webui-gfx803-c258dd34a888b7c6c9e4c9bbef76732d9d7db6e7.tar.gz stable-diffusion-webui-gfx803-c258dd34a888b7c6c9e4c9bbef76732d9d7db6e7.tar.bz2 stable-diffusion-webui-gfx803-c258dd34a888b7c6c9e4c9bbef76732d9d7db6e7.zip |
Fix UnicodeEncodeError when writing to file CLIP Interrogator Batch Mode
The code snippet print(interrogation_function(img), file=open(os.path.join(ii_output_dir, f"{left}.txt"), 'a')) raises a UnicodeEncodeError with the message "'charmap' codec can't encode character '\u016b' in position 129". This error occurs because the default encoding used by the open() function cannot handle certain Unicode characters.
To fix this issue, the encoding parameter needs to be explicitly specified when opening the file. By using an appropriate encoding, such as 'utf-8', we can ensure that Unicode characters are properly encoded and written to the file.
The updated code should be modified as follows:
python
Copy code
print(interrogation_function(img), file=open(os.path.join(ii_output_dir, f"{left}.txt"), 'a', encoding='utf-8'))
By making this change, the code will no longer raise the UnicodeEncodeError and will correctly handle Unicode characters during the file write operation.
Diffstat (limited to 'modules/ui.py')
-rw-r--r-- | modules/ui.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/modules/ui.py b/modules/ui.py index e2e3b6da..10e35ec3 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -155,7 +155,7 @@ def process_interrogate(interrogation_function, mode, ii_input_dir, ii_output_di img = Image.open(image)
filename = os.path.basename(image)
left, _ = os.path.splitext(filename)
- print(interrogation_function(img), file=open(os.path.join(ii_output_dir, f"{left}.txt"), 'a'))
+ print(interrogation_function(img), file=open(os.path.join(ii_output_dir, f"{left}.txt"), 'a', encoding='utf-8'))
return [gr.update(), None]
|