wishwakankanamg commited on
Commit
1cd15a0
·
1 Parent(s): 6379f20
Files changed (1) hide show
  1. app.py +12 -29
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 and len(result["messages"]) > 0:
49
- answer = result["messages"][-1].content
50
- return str(answer)
51
- return "No answer generated"
52
-
53
-
54
- # demo = gr.Interface(
55
- # fn=run_langgraph_agent,
56
- # inputs=gr.Textbox(lines=2, placeholder="Enter your message..."),
57
- # outputs="text",
58
- # title="LangGraph Agent Chat",
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()