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.:
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
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
- Trying to upgrade gradio, but even when to remove or replace replaces of \n to <br>, still outout in UI is wrong and all compressed. But somehow copy-paste of that text pops back to having the missin... — committed to h2oai/h2ogpt by pseudotensor a year ago
- Fix and test to work-around https://github.com/gradio-app/gradio/issues/4344#issuecomment-1584925330 — committed to h2oai/h2ogpt by pseudotensor a year ago
- Downgrade gradio client until https://github.com/gradio-app/gradio/issues/4344 fixed again. — committed to h2oai/h2ogpt by pseudotensor 9 months ago
- Give control over rendering markdown or not (only option at CLI time for now) to work-around https://github.com/gradio-app/gradio/issues/4344#issuecomment-1771963021 . Add total number of docs used i... — committed to h2oai/h2ogpt by pseudotensor 8 months ago
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 forgr.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 aline_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.