I am trying to load a custom PNG image as an avatar in st.chat_message using st.image. Here’s my code:
import streamlit as st
import streamlit_shadcn_ui as ui
st.title('Hello World!')
st.write('This is a simple example of a Streamlit app.')
while True:
for i in range(50):
if i % 2 == 0:
col1, col2 = st.columns([1,4])
with col1:
# with st.chat_message('Momos', avatar=':material/man:'):
with st.chat_message('Momos', avatar=st.image('./jonathan.png', width=50)):
st.write(i)
else:
col1, col2 = st.columns([4,1])
with col2:
with st.chat_message('Momos', avatar=st.image('./jonathan.png', width=50)):
st.write(i)
The app is loading the image, I can see it on the app page. But then I am getting the following error:
File "D:\repositories\streamlit\.venv\Lib\site-packages\streamlit\elements\widgets\chat.py", line 106, in _process_avatar_input
raise StreamlitAPIException(
"Failed to load the provided avatar value as an image."
) from ex
streamlit.errors.StreamlitAPIException: Failed to load the provided avatar value as an image.
It’s an image I downloaded from Robohash.