Andy Guyader commited on
Commit
557e797
·
1 Parent(s): 87fea27

Add application file

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Initialize session state to store chat history
4
+ if "messages" not in st.session_state:
5
+ st.session_state["messages"] = []
6
+
7
+ # Function for chatbot responses
8
+ def chatbot_response(user_input):
9
+ if user_input.endswith("?"):
10
+ return "Yes"
11
+ else:
12
+ return "Ask me anything!"
13
+
14
+ # Streamlit app layout
15
+ st.title("Simple Chatbot")
16
+ st.markdown("Ask me any yes/no question or anything else!")
17
+
18
+ # Display chat history
19
+ st.markdown("### Chat History")
20
+ for user, bot in st.session_state["messages"]:
21
+ st.markdown(f"**You:** {user}")
22
+ st.markdown(f"**Bot:** {bot}")
23
+
24
+ # User input
25
+ user_input = st.text_input("Your message:", key="user_input")
26
+
27
+ # When user submits input
28
+ if user_input:
29
+ # Get chatbot response
30
+ bot_response = chatbot_response(user_input)
31
+ # Append the interaction to chat history
32
+ st.session_state["messages"].append((user_input, bot_response))
33
+ # Clear input box
34
+ st.experimental_rerun()