Hello all, I am having some trouble with deploying my streamlit app to the cloud and having the Chat avatars show up. Right now I have it working 100% on my local machine, but when I deploy it the only thing that does not work is the avatar images, I get a broken image link for the user and the bot images.
I can display these images just fine using st.image both on my local machine and the cloud. On my local machine I can display them just fine using the avatar = bot_image - but the avatar option does not work on the cloud.
The images are directly loaded into the same location on GitHub as my code. This is confirmed by the fact that the st.image works. What am I missing? Why can’t I utilize my avatar images on the cloud but I can on my local machine?
According to the Documentation, the avatar parameter accepts the URL to the image.
I’ve did a test using various approaches on the Streamlit Community Cloud and the following works for displaying a custom avatar image:
with st.chat_message('assistant', avatar='https://raw.githubusercontent.com/dataprofessor/streamlit-chat-avatar/master/bot-icon.png'):
st.write('Hello world!')
Here’s the code to my test and the working solution was option 1 using the full URL path to the image:
import streamlit as st
from PIL import Image
st.info('Default')
with st.chat_message('assistant'):
st.write('Hello world!')
st.warning('1. URL full path')
with st.chat_message('assistant', avatar='https://raw.githubusercontent.com/dataprofessor/streamlit-chat-avatar/master/bot-icon.png'):
st.write('Hello world!')
st.warning('2. URL relative path')
with st.chat_message('assistant', avatar='bot-icon.png'):
st.write('Hello world!')
st.warning('3. URL relative path 2')
with st.chat_message('assistant', avatar='./bot-icon.png'):
st.write('Hello world!')
st.warning('4. URL relative path with Image.open')
with st.chat_message('assistant', avatar=Image.open('bot-icon.png')):
st.write('Hello world!')
# Icon Credit
# https://www.flaticon.com/free-icon/bot_4712027
Trying to implement this now, will report back when I either fix or don’t fix it. What you display for everything but Option 1 is what I’m experiencing. Thanks!
I had the same avatar issue as you. Both at first when deploying my app (it was working locally but not on the cloud), and then using Chanin’s fix. It still wouldn’t work.
But by paying more attention to the link of my image, I managed to make it work.
The trick is indeed to use the url of the image hosted on github as the source of the avatar, but you have to use the raw.githubusercontent.com url, and not the github.com url!
You also have to make sure your repo is public! If not, it can’t access the image url you provide and won’t work. Either make your whole repo public, or keep your main repo private and create a second public repo with only those images (that’s what I did).
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.