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

[기술 조사] Streamlit 웹 채팅 #1

Open
GITSangWoo opened this issue Aug 25, 2024 · 0 comments
Open

[기술 조사] Streamlit 웹 채팅 #1

GITSangWoo opened this issue Aug 25, 2024 · 0 comments

Comments

@GITSangWoo
Copy link
Contributor

GITSangWoo commented Aug 25, 2024

팀원과 공유하고 싶은 내용 자유롭게 작성
[streamlit]
https://docs.streamlit.io/develop/api-reference/chat

로그인해서 유저이름을 받고 유저이름이면 경고가 뜨고
유저이름 : 메세지 출력이 되는 채팅방 코드

import streamlit as st


if 'messages' not in st.session_state:
    st.session_state.messages = []

if 'username' not in st.session_state:
    st.session_state.username =""
    st.session_state.ready = False


if not st.session_state.ready:
    st.title("채팅방 로그인")
    st.write("채팅방에 로그인하기 위해서는 이름을 입력해주세요")
    username_input = st.text_input("이름을 입력하세요:", st.session_state.username)

    if st.button("입력"):
        username_input = username_input.strip()
        if username_input:
            st.session_state.username = username_input
            st.session_state.ready =True
            st.write(f"안녕하세요, {st.session_state.username}!")
            st.rerun()
        else :
            st.error("이름은 공백일 수 없습니다")

else :
    st.title(f"채팅방에 오신걸 환영합니다. {st.session_state.username}님!")
    message = st.chat_input("채팅을 입력하세여")
    if message :
       st.session_state.messages.append(f"{st.session_state.username}:{message}")
       if st.session_state.messages:
            for messages in st.session_state.messages:
                st.write(messages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant