Skip to content
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

When using st.chat_input to enter a message, the message sometimes disappears immediately after input. #97

Closed
yokei-dev opened this issue Nov 13, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@yokei-dev
Copy link

yokei-dev commented Nov 13, 2023

Summary

When using st.chat_input to enter a message, the message sometimes disappears immediately after input.

Video

2023-11-13.16.58.30.mov

Investigation

This issue did not occur before the introduction of streamlit_authenticator, but it started happening after its integration.

Hypothesis

I suspect that something is causing a rerun after message input, which might be leading to the disappearance of the entered message.

Sample code

import streamlit as st
import openai
import os
import yaml
from yaml.loader import SafeLoader
import streamlit_authenticator as stauth

openai.api_key = os.environ["OPENAI_API_KEY"]

USER_NAME = "user"
ASSISTANT_NAME = "assistant"

with open('./config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)

usernames = ["****"]
passwords = ["****"]

user_dict = {username: {'name': username, 'password': passwords} for username, passwords in zip(usernames, passwords)}
credentials = {'usernames': user_dict}

authenticator = stauth.Authenticate(
    credentials,
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['preauthorized']
)

name, authentication_status, username = authenticator.login('Login', 'main')

def show_chat_log():
    ****
def chat_log_to_text():
    ****
def response_chatgpt():
    ****

def logged_in_page():

    user_message = st.chat_input("input your message")

    if user_message:

        show_chat_log()

        with st.chat_message(USER_NAME):
            st.write(user_message)

        response = response_chatgpt(
            user_message,
        )
        with st.chat_message(ASSISTANT_NAME):
            ****

if st.session_state["authentication_status"]:
    st.write(f'Welcome *{st.session_state["name"]}*')
    authenticator.logout('Logout', 'main', key='unique_key')
    logged_in_page()
elif st.session_state["authentication_status"] is False:
    st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] is None:
    st.warning('Please enter your username and password')

@mkhorasani can you please help, would be greatly appreciated

@mkhorasani mkhorasani added the duplicate This issue or pull request already exists label Jan 22, 2024
@mkhorasani
Copy link
Owner

mkhorasani commented May 15, 2024

I will be closing this issue, and request that you kindly follow developments in #99.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants