a chatbot that allows sending support tickets
To upload files, please first save the app
"""
- This chatbot replies with the reversed input message
- If you send the word ticket, it'll prompt you to submit a form
"""
import streamlit as st
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
if "show_ticket_form" not in st.session_state:
st.session_state.show_ticket_form = False
st.title("Simple Chatbot Application")
# Container for chat messages
messages = st.container()
# Chat input widget
if prompt := st.chat_input("Say something"):
# Append user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
with messages:
for msg in st.session_state.messages:
st.chat_message(msg["role"]).write(msg["content"])
# Generate assistant response
if prompt == "ticket":
st.session_state.show_ticket_form = True
assistant_response = prompt[::-1]
# Append assistant message to chat history
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
st.chat_message("assistant").write(assistant_response)
@st.dialog("Submit a Ticket")
def ticket_form():
with st.form("ticket_form"):
st.write("Please fill in the ticket details below:")
ticket_detail = st.text_input("Ticket Detail", "")
submitted = st.form_submit_button("Submit")
if submitted:
st.session_state.show_ticket_form = False
st.success(f"Ticket submitted successfully! {ticket_detail}")
if st.session_state.show_ticket_form:
ticket_form()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?