-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues with local image as st.chat_message
avatar
#7130
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dda4284
Fix issues with local image as message avatar
LukasMasuch ddc6547
Add chat message e2e playwright test
LukasMasuch e013c43
Fix unit test issue
LukasMasuch 64b7357
Update chat message snapshots
LukasMasuch affb650
Wait until images have loaded
LukasMasuch 84579ed
Add second message reusing the same image
LukasMasuch 56ce2a4
Increment counter
LukasMasuch 84b9bd8
Add additional snapshot
LukasMasuch 14c3aba
Change timeout
LukasMasuch 443a501
Change how we wait for image to load
LukasMasuch 74dfbb2
Add missing snapshot
LukasMasuch File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+2.52 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-0[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.09 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-0[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.34 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-0[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.26 KB
...t/snapshots/linux/st_chat_message_test/chat_message-0[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.86 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-0[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.11 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-0[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-1[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.2 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-1[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.3 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-1[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...t/snapshots/linux/st_chat_message_test/chat_message-1[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.3 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-1[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-1[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.6 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-2[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.1 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-2[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.96 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-2[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...t/snapshots/linux/st_chat_message_test/chat_message-2[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.3 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-2[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-2[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.7 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-3[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.4 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-3[dark_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-3[dark_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.4 KB
...t/snapshots/linux/st_chat_message_test/chat_message-3[light_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.3 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-3[light_theme-firefox].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-3[light_theme-webkit].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.2 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-4[dark_theme-chromium].png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-4[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+20 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-4[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+22.2 KB
...t/snapshots/linux/st_chat_message_test/chat_message-4[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+33.8 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-4[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+20 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-4[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+4.78 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-5[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+7.2 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-5[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+4.49 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-5[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+4.84 KB
...t/snapshots/linux/st_chat_message_test/chat_message-5[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+7.12 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-5[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+4.53 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-5[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+1.99 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-6[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+2.39 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-6[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+1.81 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-6[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+1.67 KB
...t/snapshots/linux/st_chat_message_test/chat_message-6[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+2.09 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-6[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-6[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+2.85 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-7[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.84 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-7[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.63 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-7[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+2.83 KB
...t/snapshots/linux/st_chat_message_test/chat_message-7[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.74 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-7[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.58 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-7[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+2.52 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-8[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.51 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-8[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.32 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-8[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+2.5 KB
...t/snapshots/linux/st_chat_message_test/chat_message-8[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+3.46 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-8[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+2.31 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-8[light_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+3.7 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-9[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+5.57 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-9[dark_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+3.47 KB
...ight/snapshots/linux/st_chat_message_test/chat_message-9[dark_theme-webkit].png
Oops, something went wrong.
Binary file added
BIN
+3.75 KB
...t/snapshots/linux/st_chat_message_test/chat_message-9[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+5.51 KB
...ht/snapshots/linux/st_chat_message_test/chat_message-9[light_theme-firefox].png
Oops, something went wrong.
Binary file added
BIN
+3.5 KB
...ght/snapshots/linux/st_chat_message_test/chat_message-9[light_theme-webkit].png
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from PIL import Image | ||
|
||
import streamlit as st | ||
|
||
np.random.seed(0) | ||
|
||
|
||
# Generate a random dataframe | ||
df = pd.DataFrame( | ||
np.random.randn(5, 5), | ||
columns=("col_%d" % i for i in range(5)), | ||
) | ||
|
||
|
||
with st.chat_message("user"): | ||
st.write("Hello…") | ||
|
||
with st.chat_message("assistant"): | ||
st.write( | ||
""" | ||
Hello, here is a code snippet: | ||
|
||
```python | ||
import streamlit as st | ||
with st.chat_message("assistant"): | ||
st.write("Hello, here is a code snippet...") | ||
``` | ||
""" | ||
) | ||
|
||
with st.chat_message("user", avatar="🧑"): | ||
st.write( | ||
""" | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique est | ||
at tincidunt pul vinar. Nam pulvinar neque sapien, eu pellentesque metus pellentesque | ||
at. Ut et dui molestie, iaculis magna sed. | ||
""" | ||
) | ||
|
||
with st.chat_message("dog", avatar="https://static.streamlit.io/examples/dog.jpg"): | ||
st.write("Woof woof! I'm a dog and I like charts:") | ||
st.line_chart(df, use_container_width=True) | ||
|
||
cat = st.chat_message("cat", avatar="https://static.streamlit.io/examples/cat.jpg") | ||
cat.write("I'm a cat and I like this dataset:") | ||
cat.dataframe(df, use_container_width=True) | ||
cat.text_input("What's your name?") | ||
|
||
|
||
with st.chat_message("Bot"): | ||
with st.expander("See more", expanded=True): | ||
st.write("Lorem ipsum dolor sit amet") | ||
|
||
st.chat_message("human") | ||
|
||
|
||
image1 = Image.new("RGB", (10, 10), "red") | ||
st.chat_message("user", avatar=image1).write("Red local image") | ||
|
||
image2 = Image.new("RGB", (10, 10), "blue") | ||
st.chat_message("assistant", avatar=image2).write("Blue local image") | ||
st.chat_message("assistant", avatar=image2).write( | ||
"Another message with the same blue avatar." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from conftest import ImageCompareFunction | ||
|
||
|
||
def test_renders_chat_messages_correctly_1( | ||
themed_app: Page, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test if the chat messages render correctly""" | ||
# Wait a bit more to allow all images to load: | ||
chat_message_elements = themed_app.locator(".stChatMessage") | ||
expect(chat_message_elements).to_have_count(10) | ||
for i, element in enumerate(chat_message_elements.all()): | ||
element.scroll_into_view_if_needed() | ||
# Wait a bit more to allow the avatar images to load: | ||
themed_app.wait_for_timeout(100) | ||
assert_snapshot(element, name=f"chat_message-{i}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukasMasuch one question I have, since I am not super familiar with the
chat_message
design.Is
self.dg._get_delta_path_str()
return unique "coordinates" for different chat_messages?I looked into the
media_file_manager
implementation and looks like this should not cause "multiple uploads of the same file" / "unwanted premature file removals for the file" issues.Just to confirm that everything works correctly, could we add another playwright check where we check that the same image used multiple times as an avatar for different
chat_message
doesn't cause any errors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oki 👍 I added one more e2e check that reuses the same local image. Does that cover it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that covers exactly that case :)