Fix an encoding issue in gradio/components/code.py (#8077)

* Fix an enconding issue in gradio/components/code.py

Changes Made:
Modified the postprocess function in gradio/components/code.py to handle file encoding properly.
Added encoding="utf-8" parameter to the open function when reading code files. I hardcoded UTF-8 because I couldn't figure out how to specify the encoding, similar to the fix in gradio-app#8075. My issue is gradio-app#8076

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
3210448723 2024-04-20 04:05:55 +08:00 committed by GitHub
parent 2afca65419
commit d7461aab51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Fix an encoding issue in gradio/components/code.py

View File

@ -151,7 +151,7 @@ class Code(Component):
if value is None:
return None
elif isinstance(value, tuple):
with open(value[0]) as file_data:
with open(value[0], encoding="utf-8") as file_data:
return file_data.read()
else:
return value.strip()