Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ if not tavily_api_key:
|
|
| 23 |
raise ValueError("Missing required environment variable: TAVILY_API_KEY")
|
| 24 |
|
| 25 |
# ------------------- Tool Definitions -------------------
|
|
|
|
| 26 |
tavily_tool = TavilySearchResults(max_results=5)
|
| 27 |
|
| 28 |
def multiply(a: int, b: int) -> int:
|
|
@@ -61,24 +62,22 @@ app_graph.add_conditional_edges("assistant", tools_condition)
|
|
| 61 |
app_graph.add_edge("tools", "assistant")
|
| 62 |
react_graph = app_graph.compile()
|
| 63 |
|
| 64 |
-
#
|
| 65 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile:
|
| 66 |
-
graph_image_path = tmpfile.name
|
| 67 |
graph = react_graph.get_graph(xray=True)
|
| 68 |
-
graph.draw_mermaid_png(
|
|
|
|
| 69 |
|
| 70 |
# ------------------- Streamlit Interface -------------------
|
| 71 |
-
st.title("ReAct Agent")
|
| 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(
|
| 79 |
-
|
| 80 |
-
placeholder="Example: 'Add 3 and 4. Multiply the result by 2. Divide it by 5.'"
|
| 81 |
-
)
|
| 82 |
|
| 83 |
if st.button("Submit"):
|
| 84 |
if not user_question.strip():
|
|
@@ -96,7 +95,7 @@ if st.button("Submit"):
|
|
| 96 |
|
| 97 |
st.success("Processing complete!")
|
| 98 |
|
| 99 |
-
# Example
|
| 100 |
st.sidebar.subheader("Example Questions")
|
| 101 |
st.sidebar.write("- Add 3 and 4. Multiply the result by 2. Divide it by 5.")
|
| 102 |
st.sidebar.write("- Tell me how many centuries Virat Kohli scored.")
|
|
|
|
| 23 |
raise ValueError("Missing required environment variable: TAVILY_API_KEY")
|
| 24 |
|
| 25 |
# ------------------- Tool Definitions -------------------
|
| 26 |
+
# Tavily Search Tool
|
| 27 |
tavily_tool = TavilySearchResults(max_results=5)
|
| 28 |
|
| 29 |
def multiply(a: int, b: int) -> int:
|
|
|
|
| 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 = react_graph.get_graph(xray=True)
|
| 68 |
+
tmpfile.write(graph.draw_mermaid_png()) # Write binary image data to file
|
| 69 |
+
graph_image_path = tmpfile.name
|
| 70 |
|
| 71 |
# ------------------- Streamlit Interface -------------------
|
| 72 |
+
st.title("ReAct Agent with Arithmetic and Search")
|
| 73 |
|
| 74 |
# Display the workflow graph
|
| 75 |
st.header("LangGraph Workflow Visualization")
|
| 76 |
st.image(graph_image_path, caption="LangGraph Workflow Visualization")
|
| 77 |
|
| 78 |
# Prompt user for inputs
|
| 79 |
+
user_question = st.text_area("Enter your question:",
|
| 80 |
+
placeholder="Example: 'Add 3 and 4. Multiply the result by 2. Divide it by 5.'")
|
|
|
|
|
|
|
| 81 |
|
| 82 |
if st.button("Submit"):
|
| 83 |
if not user_question.strip():
|
|
|
|
| 95 |
|
| 96 |
st.success("Processing complete!")
|
| 97 |
|
| 98 |
+
# Example Placeholder Suggestions
|
| 99 |
st.sidebar.subheader("Example Questions")
|
| 100 |
st.sidebar.write("- Add 3 and 4. Multiply the result by 2. Divide it by 5.")
|
| 101 |
st.sidebar.write("- Tell me how many centuries Virat Kohli scored.")
|