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

Encoding issues in newer Gradio versions #6364

Closed
1 task done
BramVanroy opened this issue Nov 10, 2023 · 6 comments
Closed
1 task done

Encoding issues in newer Gradio versions #6364

BramVanroy opened this issue Nov 10, 2023 · 6 comments
Labels
bug Something isn't working Regression Bugs did not exist in previous versions of Gradio

Comments

@BramVanroy
Copy link

Describe the bug

In 3.33.1, my gradio app could be launched perfectly fine on both Windows and Linux. However, when I upgraded to the most recent version, I was getting encoding issues left and right. I traced it back to the following line:

app_text = Path(original_path).read_text()

If I change that to the following everything works as intended.

app_text = Path(original_path).read_text(encoding="utf-8")

I understand that people may DO want to use cp1252 on Windows, or any other encoding scheme, but it'd be great to allow for more control here. Either by an environment variable or even a launch argument where a user can specify the encoding to use.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

I cloned this repo and tried to run it locally: https://huggingface.co/spaces/uonlp/open_multilingual_llm_leaderboard

Screenshot

No response

Logs

[notice] A new release of pip available: 22.3.1 -> 23.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
(leaderboard) PS F:\python\open_multilingual_llm_leaderboard> gradio .\app.py
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ F:\python\open_multilingual_llm_leaderboard\.venv\lib\site-packages\gradio\cli\commands\reload.p │
│ y:97 in main                                                                                     │
│                                                                                                  │
│    94 │   demo_path: Path, demo_name: str = "demo", watch_dirs: Optional[List[str]] = None       │
│    95 ):                                                                                         │
│    96 │   # default execution pattern to start the server and watch changes                      │
│ ❱  97 │   filename, path, watch_dirs, demo_name = _setup_config(                                 │
│    98 │   │   demo_path, demo_name, watch_dirs                                                   │
│    99 │   )                                                                                      │
│   100 │   # extra_args = args[1:] if len(args) == 1 or args[1].startswith("--") else args[2:]    │
│                                                                                                  │
│ ╭────────────── locals ──────────────╮                                                           │
│ │  demo_name = 'demo'                │                                                           │
│ │  demo_path = WindowsPath('app.py') │                                                           │
│ │ watch_dirs = []                    │                                                           │
│ ╰────────────────────────────────────╯                                                           │
│                                                                                                  │
│ F:\python\open_multilingual_llm_leaderboard\.venv\lib\site-packages\gradio\cli\commands\reload.p │
│ y:34 in _setup_config                                                                            │
│                                                                                                  │
│    31 │   additional_watch_dirs: list[str] | None = None,                                        │
│    32 ):                                                                                         │
│    33 │   original_path = demo_path                                                              │
│ ❱  34 │   app_text = Path(original_path).read_text()                                             │
│    35 │                                                                                          │
│    36 │   patterns = [                                                                           │
│    37 │   │   f"with gr\\.Blocks\\(\\) as {demo_name}",                                          │
│                                                                                                  │
│ ╭─────────────────── locals ────────────────────╮                                                │
│ │ additional_watch_dirs = []                    │                                                │
│ │             demo_name = 'demo'                │                                                │
│ │             demo_path = WindowsPath('app.py') │                                                │
│ │         original_path = WindowsPath('app.py') │                                                │
│ ╰───────────────────────────────────────────────╯                                                │
│                                                                                                  │
│ C:\Users\bramv\.pyenv\pyenv-win\versions\3.10.10\lib\pathlib.py:1135 in read_text                │
│                                                                                                  │
│   1132 │   │   """
│   1133 │   │   encoding = io.text_encoding(encoding)                                             │
│   1134 │   │   with self.open(mode='r', encoding=encoding, errors=errors) as f:                  │
│ ❱ 1135 │   │   │   return f.read()                                                               │
│   1136 │                                                                                         │
│   1137 │   def write_bytes(self, data):                                                          │
│   1138 │   │   """                                                                               │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │ encoding = 'locale'                                                     │                      │
│ │   errors = None                                                         │                      │
│ │        f = <_io.TextIOWrapper name='app.py' mode='r' encoding='cp1252'> │                      │
│ │     self = WindowsPath('app.py')                                        │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ C:\Users\bramv\.pyenv\pyenv-win\versions\3.10.10\lib\encodings\cp1252.py:23 in decode            │
│                                                                                                  │
│    20                                                                                            │
│    21 class IncrementalDecoder(codecs.IncrementalDecoder):                                       │
│    22 │   def decode(self, input, final=False):                                                  │
│ ❱  23 │   │   return codecs.charmap_decode(input,self.errors,decoding_table)[0]                  │
│    24                                                                                            │
│    25 class StreamWriter(Codec,codecs.StreamWriter):                                             │
│    26 │   pass                                                                                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ final = True                                                                                 │ │
│ │ input = b'import json\r\nfrom collections import defaultdict\r\n\r\nimport pandas as         │ │
│ │         pd\r\nimport '+4982                                                                  │ │
│ │  self = <encodings.cp1252.IncrementalDecoder object at 0x000001780C99F2B0>                   │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 3554: character maps to <undefined>

System Info

Works with 3.33.1 but not with the most recent version.

Severity

I can work around it

@BramVanroy BramVanroy added the bug Something isn't working label Nov 10, 2023
@freddyaboulton
Copy link
Collaborator

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

@BramVanroy
Copy link
Author

Sure. Is it sufficient to update this line

app_text = Path(original_path).read_text()

to something like the following, or should there also be an update to Interface or Blocks to make this easier to do without an envvar? (If so, where?)

app_text = Path(original_path).read_text(encoding=os.getenv("GRADIO_APP_ENCODING", "utf-8"))

Probably also a doc update but I'm not sure where to add this information. A dedicated page with a list of suitable environment variables would be useful. There are quite a lot here https://www.gradio.app/docs/interface#initialization

@abidlabs
Copy link
Member

cc @aliabd with regards to the documentation, but we can do that in a separate PR @BramVanroy

@abidlabs abidlabs added the Regression Bugs did not exist in previous versions of Gradio label Nov 12, 2023
@abidlabs
Copy link
Member

@BramVanroy I think that change should be sufficient. If you could go ahead and open a PR, we're happy to review more thoroughly

@curiousRay
Copy link
Contributor

curiousRay commented Dec 2, 2023

Encountered the same situation when trying to run my script which contains Chinese characters.
A PR is initiated. @BramVanroy @abidlabs @freddyaboulton

freddyaboulton added a commit that referenced this issue Dec 4, 2023
* fix: configure default encoding as utf-8

* apply doc change for the fix

* apply cn doc change for the fix

* add changeset

* Lint

---------

Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
@abidlabs
Copy link
Member

abidlabs commented Dec 6, 2023

Should be closed with #6622

@abidlabs abidlabs closed this as completed Dec 6, 2023
dawoodkhan82 pushed a commit that referenced this issue Dec 8, 2023
* fix: configure default encoding as utf-8

* apply doc change for the fix

* apply cn doc change for the fix

* add changeset

* Lint

---------

Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
abidlabs added a commit that referenced this issue Dec 13, 2023
* fix

* add changeset

* tests

* Update package.json

* Hotfix: version on changelog (#6559)

* clog version

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Fix version in other changelog (#6561)

* Fix version in other changelog

why do we have 2?

* remove changeset

* Ensure Chatbot messages are properly aligned when `rtl` is true (#6574)

* fix text alignment when rtl is true

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Improve like/dislike functionality (#6572)

* amend like/dislike logic

* add like/dislike to chatbot demo and add e2e test

* add changeset

* e2e test changes

* revert chatbot_component changes

* tweak

* generate notebooks

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Fix typo envrion -> environ (#6585)

* Feat: make UploadButton accept icon (#6584)

* feat: make UploadButton accept icon

* add changeset

* add proxy url prop

* add stories

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Make FileExplorer work on python 3.8 and 3.9. Also make it update on changes to root, glob, or glob_dir (#6550)

* Add code

* add changeset

* add changeset

* Add test

* fix

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Fix uploaded file wasn't moved to custom temp dir at different disks (#6565)

* Fix uploaded file wasn't moved to custom temp dir at different disks

* add changeset

* Update routes.py

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>

* Fix the docstring decoration (#5885)

* Fix the docstring of the `Slider` class

* add changeset

* Update the JSON file generator to output a new field .styled_description to render the inline code syntax in the description field

* add changeset

* Update style_types() to deal with backticks and single asterisks

* Update the inline style converter to use regex for the curly bracket syntax as well

* Revert `style_types()` not to touch the `description` field and update the frontend code to apply styling to such formatted texts on Svelte's side

* Apply the inline styler to other `.description` field appearances

* Apply the inline styler to `.preprocessing`, `.postprocessing`, `.examples-format`, `.events`, and `*.parameters.doc`

* Stop applying HTML styles to the JSON data, instaed apply HTML escaping

* Escape HTML tokens in .parameters[]["doc"] too

* fixes

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>

* chore(deps): update all non-major dependencies (#6593)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency jsdom to v23 (#6582)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Update zh-CN.json (#6512)

* Update zh-CN.json

* add changeset

* format

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Fix: Gradio Client work with private Spaces (#6602)

* client with private space

* add changeset

* lint

* add test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Update file_explorer.py - Fixing error if nothing selected in file_count=single mode (return None rather) (#6607)

* Update file_explorer.py

Fixing error if nothing selected in file_count=single mode (return None rather)

* add changeset

* added unit tests

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Remove 2 slider demos from docs (#6624)

* remove 2 slider demos

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Fix encoding issue #6364 of reload mode (#6622)

* fix: configure default encoding as utf-8

* apply doc change for the fix

* apply cn doc change for the fix

* add changeset

* Lint

---------

Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Quick Image + Text Component Fixes (#6635)

* fixes

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Improve video trimming and error handling (#6566)

* amend trimming logic and return original file when error occurs

* add interactive story test

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Add `show_recording_waveform` to Audio (#6551)

* add show_recording_waveform

* add changeset

* add animation

* Refactor audio component and waveform options

* formatting

* add margin before audio controls

* amend default values

* expose gr.WaveformOptions

* Tweak waveform options types and handle none

* add waveform_options to reverse_audio

* tweak bool typing

* notebook

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* chore(deps): update dependency chromatic to v10 (#6619)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update chromaui/action action to v10 (#6618)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Add concurrency_limit to ChatInterface, add IDE support for concurrency_limit  (#6653)

* concurrency limit chat interface

* add changeset

* Update gradio/chat_interface.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* format (#6658)

* Removes smooth scrolling from website (#6650)

* smooth scrolling with css

* add changeset

* formatting

* remove smooth scrolling

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* chore: update versions (#6575)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fix reload mode warning about not being able to find the app (#6660)

* Fix warning

* add changeset

* Use *

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Update HF token used in CI tests (#6671)

* fix tests

* format

* fixes

* add changeset

* fixes

* fix

* fix

* update

* update

* test client

* format

* hf token 2

* add changeset

* add env

* add envs

* tests

* env

* fixes

* test external

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* use gr.Error for audio length errors (#6672)

* use gr.Error for audio length errors

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Issue 5245: consolidate usage of requests and httpx (#6598)

* issue 5245 commit 1

* formatted

* add changeset

* fixes

* fixes

* make changes in client too

* remove requests from client

* add changeset

* add changeset

* Fixes to test_utils.py in client

* fixes in client utils.py and test_utils.py

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Remove Discourse Forum Link from Website (#6679)

* remove forum link

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Tweak to our bug issue template (#6677)

* template

* add timeouts

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Set gradio api server from env (#6666)

* Use GRADIO_API_SERVER env

* Format the code

* add changeset

* Use env GRADIO_SHARE_SERVER_ADDRESS as default share_server_address

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Render each app in the PR's spaces preview in a separate page (#6657)

* Use template response

* minor fix

* Return type hint

* add changeset

* Remove return types

* response_class=None

* Use relative path

* SPA

* remove pydantic pin

* Revert

* delete changeset

* Overflow hidden on body

* text gray

* Collapsible sidebar

* max-height

* Use search params

* document.location.search

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* perf guide (#6673)

* switch from black to ruff formatter (#6543)

* migrate from black to ruff

* fix script and dependencies

* applying ruff

* add changeset

* add changeset

* address ruff feedback

* replace linter

* fixed typing

* fix typing

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Cause `gr.ClearButton` to reset the value of `gr.State`  (#6680)

* state

* note

* add changeset

* buttons

* clear button

* lint

* if

* clear'

* reset state

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* Fix dropdown blur bug when values are provided as tuples (#6694)

* fix dropdown blur bug

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* type fix

* test

* Remove the styles from the Image/Video primitive components and Fix the container styles (#6726)

* Remove the styles from the Image/Video primitive components and Fix the container styles

* add changeset

* Fix image example size styles

* Remove border from image/Example with type=gallery

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* test fix

* add changeset

* test fix

* add changeset

* test

* test fix

* test fix audio video

* format

* fix obj file issue

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
Co-authored-by: Simon Duerr <dev@simonduerr.eu>
Co-authored-by: Xiang Liao <liao1120x@gmail.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
Co-authored-by: Dody Suria Wijaya <dody@cryptolab.net>
Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: yanlin <59528590+cibimo@users.noreply.github.com>
Co-authored-by: v-chabaux <149407738+v-chabaux@users.noreply.github.com>
Co-authored-by: Lihao Lei <leilei199708@gmail.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: cswamy <101974014+cswamy@users.noreply.github.com>
Co-authored-by: aisensiy <aisensiy@163.com>
Co-authored-by: D V <77478658+DarhkVoyd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Regression Bugs did not exist in previous versions of Gradio
Projects
None yet
Development

No branches or pull requests

4 participants