|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
from streamlit_chat import message |
|
|
|
|
|
if "history" not in st.session_state: |
|
st.session_state.history = [] |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.sender { background-color: #d1e8f6; align-self: flex-start; } |
|
.receiver { background-color: #f0f0f0; align-self: flex-end; } |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
def generate_response(input_message): |
|
|
|
return f"Echo: {input_message}" |
|
|
|
def display_chat(): |
|
for i, chat in enumerate(st.session_state.history): |
|
if chat['is_user']: |
|
message(chat['message'], key=str(i) + "_user", is_user=True, avatar_style="sender") |
|
else: |
|
message(chat['message'], key=str(i) + "_bot", avatar_style="receiver") |
|
|
|
|
|
st.title("Social Messenger Demo") |
|
col1, col2 = st.columns(2) |
|
|
|
with col1: |
|
user_input = st.text_input("Enter your message", key="input") |
|
if st.button("Send", key="send"): |
|
st.session_state.history.append({"message": user_input, "is_user": True}) |
|
|
|
with col2: |
|
if user_input: |
|
response = generate_response(user_input) |
|
st.session_state.history.append({"message": response, "is_user": False}) |
|
|
|
|
|
display_chat() |