stream_it / app.py
aguyader's picture
Update app.py
ab5cebc verified
raw
history blame contribute delete
885 Bytes
import streamlit as st
import random
# Simple chatbot logic
def chatbot_response(question):
responses = ["Yes", "No", "Maybe", "Absolutely", "Definitely not"]
return random.choice(responses)
# Streamlit App
st.title("Yes/No Question Chatbot")
st.write("Ask me any yes/no question, and I'll give you an answer!")
# Initialize session state for input clearing
if "user_input" not in st.session_state:
st.session_state["user_input"] = ""
# Input box
user_input = st.text_input("Type your question here:", value=st.session_state["user_input"], key="input_box")
if st.button("Ask"): # When the user clicks the "Ask" button
if user_input.strip():
response = chatbot_response(user_input)
st.write(f"Chatbot: {response}")
else:
st.write("Chatbot: Please ask a valid question!")
st.session_state["user_input"] = "" # Clear the input box