Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 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 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:",
|