DrishtiSharma commited on
Commit
b3a8383
·
verified ·
1 Parent(s): d0f4eb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -9,7 +9,7 @@ from langgraph.graph import START, StateGraph
9
  from langgraph.prebuilt import tools_condition
10
  from langgraph.prebuilt import ToolNode
11
  from langchain_core.messages import HumanMessage, SystemMessage
12
- from IPython.display import Image, display
13
 
14
  # ------------------- Environment Variable Setup -------------------
15
  # Fetch API keys from environment variables
@@ -62,17 +62,17 @@ app_graph.add_conditional_edges("assistant", tools_condition)
62
  app_graph.add_edge("tools", "assistant")
63
  react_graph = app_graph.compile()
64
 
65
- # Display graph visualization
66
- st.header("LangGraph Workflow Visualization")
67
- try:
68
- image_path = react_graph.get_graph(xray=True).draw_mermaid_png()
69
- display(Image(image_path))
70
- st.image(image_path, caption="LangGraph Workflow Visualization")
71
- except Exception as e:
72
- st.error(f"Failed to display graph visualization: {e}")
73
 
74
  # ------------------- Streamlit Interface -------------------
75
- #st.title("ReAct Agent with Arithmetic and Search")
 
 
 
 
76
 
77
  # Prompt user for inputs
78
  user_question = st.text_area("Enter your question:",
 
9
  from langgraph.prebuilt import tools_condition
10
  from langgraph.prebuilt import ToolNode
11
  from langchain_core.messages import HumanMessage, SystemMessage
12
+ import tempfile
13
 
14
  # ------------------- Environment Variable Setup -------------------
15
  # Fetch API keys from environment variables
 
62
  app_graph.add_edge("tools", "assistant")
63
  react_graph = app_graph.compile()
64
 
65
+ # Save graph visualization as an image
66
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile:
67
+ graph_image_path = tmpfile.name
68
+ react_graph.get_graph(xray=True).draw_mermaid_png(graph_image_path)
 
 
 
 
69
 
70
  # ------------------- Streamlit Interface -------------------
71
+ st.title("ReAct Agent with Arithmetic and Search")
72
+
73
+ # Display the workflow graph
74
+ st.header("LangGraph Workflow Visualization")
75
+ st.image(graph_image_path, caption="LangGraph Workflow Visualization")
76
 
77
  # Prompt user for inputs
78
  user_question = st.text_area("Enter your question:",