gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
30.56k stars 2.27k forks source link

UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 822129: illegal multibyte sequence #8426

Closed Col0ring closed 3 weeks ago

Col0ring commented 3 weeks ago

Describe the bug

This error is caused by the following code when using custom components with i18n code on Windows (the default encoding is 'gkb').

gradio/routes.py

  if key not in app.custom_component_hashes:
      app.custom_component_hashes[key] = hashlib.md5(
          Path(path).read_text().encode()
      ).hexdigest()

To fix it, change Path(path).read_text().encode() to Path(path).read_text(encoding="utf-8").encode().

Suggestion: the default encoding of Windows in some regions is not 'utf-8', it's better to always add the encoding parameter when reading files.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
import modelscope_studio as mgr

with gr.Blocks() as demo:
    mgr.Chatbot()

demo.launch()

Screenshot

No response

Logs

No response

System Info

system: windows
gradio version: 4.29.0
gradio_client version: 0.16.1

Severity

Blocking usage of gradio

freddyaboulton commented 3 weeks ago

Would you like to open a PR for this @Col0ring ?