gradio: Bad handling of \n in chatbot

Describe the bug

Real text output looks like:

 It's hard to say who is smarter between Isaac Newton and Albert Einstein, as both were incredibly intelligent individuals with unique perspectives on the world around them. However, here are some of the key differences between the two that may help you make a decision:

Newton was

but in gradio chatbot it looks like:

It's hard to say who is smarter between Isaac Newton and Albert Einstein, as both were incredibly intelligent individuals with unique perspectives on the world around them. However, here are some of the key differences between the two that may help you make a decision:
Newton

i.e.:

image

Even though when I copy-paste the text from the gradio UI, it somehow expands as text to be correct:

It's hard to say who is smarter between Isaac Newton and Albert Einstein, as both were incredibly intelligent individuals with unique perspectives on the world around them. However, here are some of the key differences between the two that may help you make a decision:

Newton

I’ve noticed alot of variability in the handling of \n. In prior gradio==3.31.0, I could convert “\n” to “
” and it fixed the problem.

However, in gradio==3.32.0 this no longer works, and the “
” show up literally in the chat output. I have not found any work around.

I debugged the code itself, and the “processed_messages” still looks fine. So it’s “just” the UI itself that is wrongly displaying \n. I presume this is related to how new lines in html don’t directly matter, but
showing up literally in chatbot now is new to me.

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

As above

Screenshot

image

Logs

NA

System Info

gradio==3.32.0

Severity

blocking upgrade to latest gradio version

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 28 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Hi folks, we discussed internally and agreed with your suggestion of reverting the change.

By default, the gr.Chatbot will render single new lines as new lines (so render Markdown the way that GitHub does it as opposed to Common Spec). Same for gr.DataFrame. On the other hand, gr.Markdown will continue rendering Markdown according to Common Spec, the way it has always rendered Markdown. We’ve also introduced a line_breaks parameter to all three components for developers to be able to control this behavior as desired.

See: https://github.com/gradio-app/gradio/pull/5755, which should be out soon.