File size: 2,119 Bytes
bfbb419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# import streamlit as st

# # Load CSS
# def load_css(file_name):
#     with open(file_name) as f:
#         st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)

# load_css("style.css") 

# # Your Streamlit chat input component
# with st.form("my_form"):
#     text_input = st.text_input("Enter your message:")
#     submit_button = st.form_submit_button("Send")
# import streamlit as st

# # Load CSS 
# def load_css(file_name):
#     with open(file_name) as f:
#         st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)

# load_css("style.css")  

# # Create a container for the chat
# chat_container = st.container()

# with chat_container:
#     with st.form("my_form"):
#         text_input = st.text_input("Enter your message:")
#         submit_button = st.form_submit_button("Send")


import streamlit as st
from streamlit_chat import message

# Initialize session state
if "history" not in st.session_state:
    st.session_state.history = []

# Styling (adjust as needed)
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):
    # Placeholder for now; you'll likely plug in an AI model here
    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")

# App Layout
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 the chat history 
display_chat()