Update app.py
Browse files
app.py
CHANGED
@@ -2,28 +2,62 @@ import streamlit as st
|
|
2 |
from utils import get_answer
|
3 |
|
4 |
# Streamlit app layout
|
5 |
-
st.title("
|
6 |
-
st.write("Welcome to the chatbot. Ask me anything regarding Israel
|
7 |
|
8 |
# Session state to store the conversation
|
9 |
if 'conversation' not in st.session_state:
|
10 |
st.session_state.conversation = []
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Display conversation
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from utils import get_answer
|
3 |
|
4 |
# Streamlit app layout
|
5 |
+
st.title("Know More About Israel Hamas War")
|
6 |
+
st.write("Welcome to the chatbot. Ask me anything regarding the Israel Hamas War!")
|
7 |
|
8 |
# Session state to store the conversation
|
9 |
if 'conversation' not in st.session_state:
|
10 |
st.session_state.conversation = []
|
11 |
|
12 |
+
# Scrollable chat history
|
13 |
+
st.markdown("""
|
14 |
+
<style>
|
15 |
+
.chat-history {
|
16 |
+
max-height: 400px;
|
17 |
+
overflow-y: scroll;
|
18 |
+
padding: 10px;
|
19 |
+
border: 1px solid #ccc;
|
20 |
+
border-radius: 5px;
|
21 |
+
background-color: #f9f9f9;
|
22 |
+
}
|
23 |
+
.chat-message {
|
24 |
+
padding: 5px;
|
25 |
+
margin-bottom: 10px;
|
26 |
+
border-radius: 5px;
|
27 |
+
}
|
28 |
+
.user-message {
|
29 |
+
background-color: #d1e7dd;
|
30 |
+
text-align: right;
|
31 |
+
}
|
32 |
+
.bot-message {
|
33 |
+
background-color: #f8d7da;
|
34 |
+
}
|
35 |
+
</style>
|
36 |
+
""", unsafe_allow_html=True)
|
37 |
|
38 |
+
# Input box and send button
|
39 |
+
input_col, button_col = st.columns([4, 1])
|
40 |
+
with input_col:
|
41 |
+
user_input = st.text_input("You:", "", key="input_box", placeholder="Type your message here...")
|
42 |
|
43 |
+
with button_col:
|
44 |
+
if st.button("Send"):
|
45 |
+
if user_input:
|
46 |
+
# Get bot response
|
47 |
+
bot_response = get_answer(user_input)
|
48 |
|
49 |
+
# Append both user input and bot response to conversation
|
50 |
+
st.session_state.conversation.append(("user", user_input))
|
51 |
+
st.session_state.conversation.append(("bot", bot_response))
|
52 |
+
|
53 |
+
# Clear the input box
|
54 |
+
st.session_state.input_box = ""
|
55 |
|
56 |
# Display conversation
|
57 |
+
st.markdown('<div class="chat-history">', unsafe_allow_html=True)
|
58 |
+
for sender, message in st.session_state.conversation:
|
59 |
+
if sender == "user":
|
60 |
+
st.markdown(f'<div class="chat-message user-message">{message}</div>', unsafe_allow_html=True)
|
61 |
+
else:
|
62 |
+
st.markdown(f'<div class="chat-message bot-message">{message}</div>', unsafe_allow_html=True)
|
63 |
+
st.markdown('</div>', unsafe_allow_html=True)
|