File size: 679 Bytes
a33cc63 4241f88 a33cc63 4241f88 a33cc63 3ab6efe |
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 |
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()
|