I tried to apply this concept by selecting ".msg p { font-size:12px important!} in css, but it didn’t work.
- App is running locally
- Python: 3.8 and Streamlit: 1.27.2
I tried to apply this concept by selecting ".msg p { font-size:12px important!} in css, but it didn’t work.
Try selecting the p
tags in the stChatMessageContent
class
import streamlit as st
st.markdown(
"""
<style>
[data-testid="stChatMessageContent"] p{
font-size: 1.5rem;
}
</style>
""", unsafe_allow_html=True
)
"""
# A Title
Some normal text outside the chat
"""
with st.chat_message("user"):
"""
This text is inside the chat message
"""
with st.chat_message("ai"):
"""
This text too
"""
with st.chat_message("human", avatar="🦟"):
"""
hehe
"""
Thank you for the response @edsaac
This solution works when I use st.chat_message()
, but it’s not applying to my case.
I am using message
from streamlit in my code and trying to style it.
from streamlit_chat import message
st.session_state.messages.append(SystemMessage(content='I am trying style this'))
for i, msg in enumarate(st.session_state.messages1:):
message(msg.content, is_user=False, key=f'{i})
I tried a few different ways to css selector to work using st.markdow
like how you used, but still no luck. Would you mind suggest more options?
Ah I assumed you were using the streamlit’s own chat elements and not an external component. The CSS you define with st.markdown won’t affect external components because they are their own iframe
. In this case, each message is its own iframe :/
.
Here is a bad idea:
streamlit_chat
accepts html so you could pass strings with some custom text size. Here is a bad implementation to override the streamlit_chat.message
function so it accepts a font size and wraps everything in another p
tag.
import streamlit as st
from streamlit_chat import message as msg
def message(txt:str, size="1.25rem", **kwargs):
styled_text = f"""<p style="font-size:{size};">{txt}</p>"""
msg(styled_text, allow_html=True, **kwargs)
message("My message")
message("Hello bot!", size="2rem", is_user=True)
message("Big hi!", size="6rem")
But it’s probably not good idea to default the allow_html
to True
if you expect user input.
hi ! you can refer this docs to change your font size as per your needs
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.