SimpleApp / app.py
ricardo-lsantos's picture
Update app.py
78c8fe7 verified
# import openai
import streamlit as st
from Models import HFAgent
def initMessages():
if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant", "content": "Hello, Sir. How can I assist you today, Sir?"}]
def showMessages():
for msg in st.session_state.messages:
st.chat_message(msg["role"]).write(msg["content"])
# def sidebar():
# with st.sidebar:
# st.title("Settings")
def appendMessage(role, content):
st.session_state.messages.append({"role": role, "content": content})
def writeMessage(role, content):
st.chat_message(role).write(content)
def generateHFResponse():
if "agent" not in st.session_state:
st.session_state["agent"] = HFAgent.HFAgent()
agent = st.session_state.agent
new_messages = agent(st.session_state.messages)
return new_messages[-1]
def app():
# sidebar()
st.title("🗨️ Chatbot with Stark Model")
initMessages()
showMessages()
if prompt := st.chat_input():
appendMessage("user", prompt)
writeMessage("user", prompt)
msg = generateHFResponse()
appendMessage(msg["role"], msg["content"])
writeMessage(msg["role"], msg["content"])
if __name__ == "__main__":
app()