a chatbot that allows sending support tickets
To upload files, please first save the app
import streamlit as st
from sqlalchemy import create_engine, Column, Integer, String, Text
from sqlalchemy.orm import Session, DeclarativeBase
class Base(DeclarativeBase):
pass
class Ticket(Base):
__tablename__ = 'tickets'
id = Column(Integer, primary_key=True)
subject = Column(String(100), nullable=False)
description = Column(Text, nullable=False)
engine = create_engine("sqlite:///tickets.sqlite")
Base.metadata.create_all(bind=engine)
st.title("Support Ticket Chatbot")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input
if prompt := st.chat_input("What can I help you with?"):
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
# Assuming the input contains a subject and a description for the ticket.
ticket_subject = f"Support request: {prompt}"
ticket_description = "Details about the issue."
# Store ticket in the database
with Session(engine) as session:
ticket = Ticket(subject=ticket_subject, description=ticket_description)
session.add(ticket)
session.commit()
# Display assistant response in chat message container
with st.chat_message("assistant"):
response = "Your support ticket has been created!"
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?