Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,28 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
return "Yes"
|
| 11 |
-
else:
|
| 12 |
-
return "Ask me anything!"
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
st.
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
st.
|
| 20 |
-
for user, bot in st.session_state["messages"]:
|
| 21 |
-
st.markdown(f"**You:** {user}")
|
| 22 |
-
st.markdown(f"**Bot:** {bot}")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.session_state["user_input"] = ""
|
| 35 |
|
| 36 |
-
# Display chat history
|
| 37 |
-
st.markdown("### Chat History")
|
| 38 |
-
for user, bot in st.session_state["messages"]:
|
| 39 |
-
st.markdown(f"**You:** {user}")
|
| 40 |
-
st.markdown(f"**Bot:** {bot}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
+
# Simple chatbot logic
|
| 5 |
+
def chatbot_response(question):
|
| 6 |
+
responses = ["Yes", "No", "Maybe", "Absolutely", "Definitely not"]
|
| 7 |
+
return random.choice(responses)
|
| 8 |
|
| 9 |
+
# Streamlit App
|
| 10 |
+
st.title("Yes/No Question Chatbot")
|
| 11 |
+
st.write("Ask me any yes/no question, and I'll give you an answer!")
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Initialize session state for input clearing
|
| 14 |
+
if "user_input" not in st.session_state:
|
| 15 |
+
st.session_state["user_input"] = ""
|
| 16 |
|
| 17 |
+
# Input box
|
| 18 |
+
user_input = st.text_input("Type your question here:", value=st.session_state["user_input"], key="input_box")
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
if st.button("Ask"): # When the user clicks the "Ask" button
|
| 21 |
+
if user_input.strip():
|
| 22 |
+
response = chatbot_response(user_input)
|
| 23 |
+
st.write(f"Chatbot: {response}")
|
| 24 |
+
else:
|
| 25 |
+
st.write("Chatbot: Please ask a valid question!")
|
| 26 |
+
st.session_state["user_input"] = "" # Clear the input box
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|