File size: 885 Bytes
557e797
ab5cebc
557e797
ab5cebc
 
 
 
557e797
ab5cebc
 
 
557e797
ab5cebc
 
 
557e797
ab5cebc
 
557e797
ab5cebc
 
 
 
 
 
 
557e797
803754f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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