Commit
·
1cd15a0
1
Parent(s):
6379f20
add image
Browse files
app.py
CHANGED
@@ -45,35 +45,18 @@ def show_graph():
|
|
45 |
def run_langgraph_agent(user_input: str):
|
46 |
graph = build_graph()
|
47 |
result = graph.invoke({"messages": [HumanMessage(content=user_input)]})
|
48 |
-
if "messages" in result
|
49 |
-
|
50 |
-
|
51 |
-
return
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# Create Gradio Blocks for flexible layout
|
62 |
-
with gr.Blocks() as demo:
|
63 |
-
gr.Markdown("# LangGraph Agent Chat + Graph Viewer")
|
64 |
-
|
65 |
-
with gr.Row():
|
66 |
-
with gr.Column(scale=2):
|
67 |
-
user_input = gr.Textbox(lines=2, placeholder="Enter your message...")
|
68 |
-
submit_btn = gr.Button("Send")
|
69 |
-
chat_output = gr.Textbox(label="Agent Reply")
|
70 |
-
|
71 |
-
with gr.Column(scale=1):
|
72 |
-
graph_btn = gr.Button("Show Graph")
|
73 |
-
graph_image = gr.Image(label="LangGraph Visualization")
|
74 |
-
|
75 |
-
submit_btn.click(run_langgraph_agent, inputs=user_input, outputs=chat_output)
|
76 |
-
graph_btn.click(show_graph, inputs=None, outputs=graph_image)
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
demo.launch()
|
|
|
45 |
def run_langgraph_agent(user_input: str):
|
46 |
graph = build_graph()
|
47 |
result = graph.invoke({"messages": [HumanMessage(content=user_input)]})
|
48 |
+
text_output = result["messages"][-1].content if "messages" in result else result
|
49 |
+
|
50 |
+
image = show_graph() # return PIL.Image or None
|
51 |
+
return text_output, image
|
52 |
+
|
53 |
+
|
54 |
+
demo = gr.Interface(
|
55 |
+
fn=run_langgraph_agent,
|
56 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your message..."),
|
57 |
+
outputs=[gr.Textbox(), gr.Image(type="pil")],
|
58 |
+
title="LangGraph Agent Chat",
|
59 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
if __name__ == "__main__":
|
62 |
demo.launch()
|