rakesh-dvg's picture
Update app.py
4241f88 verified
raw
history blame
679 Bytes
import gradio as gr
from langchain_core.messages import HumanMessage
from agent import assistant, AgentState
def respond(message, history=None):
history = history or []
# Append new user message
messages = history + [HumanMessage(content=message)]
state = {"messages": messages}
result = assistant(state)
# Get the response text
response_msg = result["messages"][-1].content
# Append bot response to history
history.append(HumanMessage(content=message))
history.append(HumanMessage(content=response_msg))
return response_msg, history
demo = gr.ChatInterface(respond)
if __name__ == "__main__":
demo.launch()