Harsh2001 commited on
Commit
d422eee
·
verified ·
1 Parent(s): 155dbc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -48
app.py CHANGED
@@ -3,61 +3,27 @@ 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)
 
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 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
+ # Input box for user
13
+ user_input = st.text_input("You:", "")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ if st.button("Send"):
16
+ if user_input:
17
+ # Get bot response
18
+ bot_response = get_answer(user_input)
19
 
20
+ # Append both user input and bot response to conversation
21
+ st.session_state.conversation.append(f"You: {user_input}")
22
+ st.session_state.conversation.append(bot_response)
 
 
23
 
24
+ # Clear the input box
25
+ st.experimental_rerun()
 
 
 
 
26
 
27
  # Display conversation
28
+ for line in st.session_state.conversation:
29
+ st.write(line)