Unintentional LaTeX Format in Streamlit

I have a privately deployed streamlit app that uses GPT-4o API to get information on a stock. GPT is outputting the response in markdown format. When the response contains two $ signs, the format switches to LaTeX. For example, this generated response from GPT contains $ signs:

“The premium of $4.8 is the price at which the option is trading in the market. This suggests that option traders value the potential to buy SPXL at $135 in the future (if it’s a call option) at $4.8 per share.”

When using either st.write or st.markdown to write the response to my streamlit app, the response looks like this:

I’ve tried using a function to replace ‘$’ with ‘/$’ in GPT’s response but the response formatting in streamlit is still the same.

Copying the produced GPT response in markdown into StackEdit shows the correct formatting, so it makes me think this is an issue with streamlit.

Has anyone ran into this or have any suggestions/further questions? Thanks in advance!

Perhaps you meant replacing '$' with '\$'.


Check:

Apologies, I meant to say that I used the backslash “\”. The format still shows incorrectly. Interestingly, when I write to a different page without GPT response and include backslash, the problem isn’t persisting. Is it possible to be because of something with the GPT response?

Replacing "$" by "\$" in your sample text works for me.

I believe I found the issue. I was using unnecessary textwrap functions as a part of my response. Removing these and keeping only the replace worked.

formatted_response = textwrap.dedent(response).replace('$', '\$')
to
formatted_response = response.replace('$', '\$')

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.