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

large number of problems with tex2svg taking down entire server #4084

Closed
1 task done
pseudotensor opened this issue May 6, 2023 · 4 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working pending clarification
Milestone

Comments

@pseudotensor
Copy link
Contributor

Describe the bug

h2oai/h2ogpt#47
h2oai/h2ogpt#53
h2oai/h2ogpt#59
h2oai/h2ogpt#89

Anytime some user or the chatbot makes $ type stuff, always fails and takes down entire gradio server.

Cause is here: https://github.com/gradio-app/gradio/blob/main/gradio/utils.py#L1036

Basically the text to svg is constantly failing and taking everything down.

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

Use h2oGPT and put in $ related stuff. At least 4 different versions of the problem.

Screenshot

No response

Logs

Just a couple of the cases showed in issues above.


/home/jon/miniconda3/envs/alpaca/lib/python3.10/site-packages/gradio/utils.py:901: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
  fig = plt.figure(figsize=(0.01, 0.01))
Exception ignored in: <function Image.__del__ at 0x7f4df08c4310>
Traceback (most recent call last):
  File "/home/jon/miniconda3/envs/alpaca/lib/python3.10/tkinter/__init__.py", line 4056, in __del__
    self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Pre-Generate: 2023-05-06 03:31:08.812890
Generate: 2023-05-06 03:31:08.812940
WARNING: Special characters in prompt
Exception ignored in: <function Variable.__del__ at 0x7f4df089cb80>
Traceback (most recent call last):
  File "/home/jon/miniconda3/envs/alpaca/lib/python3.10/tkinter/__init__.py", line 388, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x7f4df089cb80>
Traceback (most recent call last):
  File "/home/jon/miniconda3/envs/alpaca/lib/python3.10/tkinter/__init__.py", line 388, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x7f4df089cb80>
Traceback (most recent call last):
  File "/home/jon/miniconda3/envs/alpaca/lib/python3.10/tkinter/__init__.py", line 388, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Execution of job "clear_torch_cache (trigger: interval[0:00:20], next run at: 2023-05-06 03:31:24 PDT)" skipped: maximum number of running instances reached (1)
Ping: 2023-05-06 03:31:24.691342
Exception ignored in: <function Variable.__del__ at 0x7f4df089cb80>
Traceback (most recent call last):
  File "/home/jon/miniconda3/envs/alpaca/lib/python3.10/tkinter/__init__.py", line 388, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread

and:

            ^
ParseSyntaxException: Expected {accent | symbol | function | operatorname | group | frac | dfrac | binom | genfrac | overset | underset | sqrt | overline}, found '_'  (at char 29), (line:1, col:30)
Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/routes.py", line 401, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/blocks.py", line 1305, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/blocks.py", line 1239, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/components.py", line 4625, in postprocess
    self._postprocess_chat_messages(message_pair[0]),
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/components.py", line 4599, in _postprocess_chat_messages
    return self.md.renderInline(chat_message)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/markdown_it/main.py", line 299, in renderInline
    return self.renderer.render(self.parseInline(src, env), self.options, env)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/markdown_it/renderer.py", line 87, in render
    result += self.renderInline(token.children, options, env)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/markdown_it/renderer.py", line 108, in renderInline
    result += self.rules[token.type](tokens, i, options, env)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/mdit_py_plugins/dollarmath/index.py", line 70, in render_math_inline
    content = _renderer(str(tokens[idx].content).strip(), {"display_mode": False})
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/utils.py", line 904, in tex2svg
    fig.savefig(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/figure.py", line 3343, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 2342, in print_figure
    self.figure.draw(renderer)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/figure.py", line 3140, in draw
    mimage._draw_list_compositing_images(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/text.py", line 752, in draw
    bbox, info, descent = self._get_layout(renderer)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/text.py", line 386, in _get_layout
    w, h, d = _get_text_metrics_with_cache(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/text.py", line 97, in _get_text_metrics_with_cache
    return _get_text_metrics_with_cache_impl(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/text.py", line 105, in _get_text_metrics_with_cache_impl
    return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/backends/backend_svg.py", line 1317, in get_text_width_height_descent
    return self._text2path.get_text_width_height_descent(s, prop, ismath)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/textpath.py", line 60, in get_text_width_height_descent
    self.mathtext_parser.parse(s, 72, prop)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/mathtext.py", line 226, in parse
    return self._parse_cached(s, dpi, prop)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/mathtext.py", line 247, in _parse_cached
    box = self._parser.parse(s, fontset, fontsize, dpi)
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/matplotlib/_mathtext.py", line 1995, in parse
    raise ValueError("\n" + ParseException.explain(err, 0)) from None
ValueError: 
mysqli->error, E_USER_ERROR.__FILE__." on line ".__LINE__);<br>                        <br>
                             ^
ParseSyntaxException: Expected {accent | symbol | function | operatorname | group | frac | dfrac | binom | genfrac | overset | underset | sqrt | overline}, found '_'  (at char 29), (line:1, col:30)


### System Info

```shell
gradio==3.27.0
gradio_client==0.1.3

Severity

blocking all usage of gradio

@pseudotensor pseudotensor added the bug Something isn't working label May 6, 2023
@abidlabs abidlabs added this to the 3.x milestone May 6, 2023
@abidlabs
Copy link
Member

abidlabs commented May 6, 2023

Hi @pseudotensor I'm pretty sure this has been fixed here: #4029

Can you try installing gradio from main by following the instructions here: https://gradio.app/docs/main? We'll probably do a release early next week.

@abidlabs
Copy link
Member

abidlabs commented May 9, 2023

Hi @pseudotensor gradio==3.29.0 is out with the fix. If this does not work for you, please feel free to reopen with a minimal working example.

@abidlabs abidlabs closed this as completed May 9, 2023
@pseudotensor
Copy link
Contributor Author

pseudotensor commented Jun 13, 2023

Still get this after newest gradio etc.:

Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/routes.py", line 414, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/blocks.py", line 1326, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/blocks.py", line 1260, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/components.py", line 4660, in postprocess
    self._postprocess_chat_messages(message_pair[0]),
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/components.py", line 4631, in _postprocess_chat_messages
    chat_message = cast(str, self.md.render(chat_message))
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/markdown_it/main.py", line 267, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/markdown_it/renderer.py", line 87, in render
    result += self.renderInline(token.children, options, env)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/markdown_it/renderer.py", line 108, in renderInline
    result += self.rules[token.type](tokens, i, options, env)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/mdit_py_plugins/dollarmath/index.py", line 70, in render_math_inline
    content = _renderer(str(tokens[idx].content).strip(), {"display_mode": False})
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/gradio/utils.py", line 801, in tex2svg
    fig.savefig(
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/figure.py", line 3343, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2342, in print_figure
    self.figure.draw(renderer)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/figure.py", line 3140, in draw
    mimage._draw_list_compositing_images(
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/text.py", line 752, in draw
    bbox, info, descent = self._get_layout(renderer)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/text.py", line 386, in _get_layout
    w, h, d = _get_text_metrics_with_cache(
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/text.py", line 97, in _get_text_metrics_with_cache
    return _get_text_metrics_with_cache_impl(
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/text.py", line 105, in _get_text_metrics_with_cache_impl
    return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/backends/backend_svg.py", line 1317, in get_text_width_height_descent
    return self._text2path.get_text_width_height_descent(s, prop, ismath)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/textpath.py", line 60, in get_text_width_height_descent
    self.mathtext_parser.parse(s, 72, prop)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/mathtext.py", line 226, in parse
    return self._parse_cached(s, dpi, prop)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/mathtext.py", line 247, in _parse_cached
    box = self._parser.parse(s, fontset, fontsize, dpi)
  File "/home/user/.pyenv/versions/3.10.12/lib/python3.10/site-packages/matplotlib/_mathtext.py", line 1995, in parse
    raise ValueError("\n" + ParseException.explain(err, 0)) from None
ValueError: 
$"({DateTime.Now}): Benutzer: {HttpContext.User.Claims.FirstOrDefault(****.Type == "name")?.Value} istRolleTrainer: {HttpContext.User.IsInRole("API.Trainer")} inGruppeTrainer: {HttpContext.User.Claims.Any(****.Value.Contains("SZ_DKB_Trainer"))}");<br><br>                if (User.Claims != null && User.Claims.Any())<br>                {<br>                    int max = User.Claims.Max(****.Type.Length);<br><br>                    Console.WriteLine();<br>                    Console.WriteLine($
^
ParseException: Expected end of text, found '$'  (at char 0), (line:1, col:1)

@abidlabs
Copy link
Member

Hi @pseudotensor can you please provide a repro?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending clarification
Projects
None yet
Development

No branches or pull requests

2 participants