forked from streamlit/streamlit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue for st.camera_input and chat_input, add regression test for…
… file_uploader (streamlit#7646) Add playwright regression test for issue With st.file_uploader and st.chat_input, first message disappears streamlit#7556 Replicate changes from Ensure file_uploader doesn't trigger needless reruns streamlit#7641 for st.camera_input
- Loading branch information
Showing
4 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
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,49 @@ | ||
# 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 time | ||
|
||
import streamlit as st | ||
|
||
if "messages" not in st.session_state: | ||
st.session_state.messages = [] | ||
|
||
# A count to record the index of dialog | ||
if "count" not in st.session_state: | ||
st.session_state.count = 0 | ||
|
||
for message in st.session_state.messages: | ||
with st.chat_message(message["role"]): | ||
st.markdown(message["content"]) | ||
|
||
uploaded_files = st.sidebar.file_uploader(label="Upload", accept_multiple_files=True) | ||
|
||
for file in uploaded_files: | ||
st.sidebar.write(file.name) | ||
|
||
if prompt := st.chat_input("What is up?"): | ||
# Display user message in chat message container | ||
with st.chat_message("user"): | ||
st.markdown(prompt) | ||
# Add user message to chat history | ||
st.session_state.messages.append({"role": "user", "content": prompt}) | ||
st.session_state.count += 1 | ||
|
||
# Sleep one second here to simulate the process of assistant. | ||
time.sleep(1) | ||
with st.chat_message("assistant"): | ||
assistant = f"Good at {st.session_state.count}" | ||
st.markdown(assistant) | ||
# Add assistant message to chat history | ||
st.session_state.messages.append({"role": "assistant", "content": assistant}) |
27 changes: 27 additions & 0 deletions
27
e2e_playwright/st_chat_input_file_uploader_regression_test.py
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,27 @@ | ||
# 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 e2e_playwright.conftest import wait_for_app_run | ||
|
||
|
||
def test_regression_with_file_uploader_and_chat_input(app: Page): | ||
"""Test issue described in https://github.com/streamlit/streamlit/issues/7556.""" | ||
chat_input_element = app.get_by_test_id("stChatInput").first | ||
chat_input_element.fill("Hello world!") | ||
chat_input_element.press("Enter") | ||
wait_for_app_run(app) | ||
last_chat_message = app.get_by_test_id("stChatMessageContent").last | ||
expect(last_chat_message).to_have_text("Good at 1", use_inner_text=True) |
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