naman1102 commited on
Commit
66102de
Β·
1 Parent(s): 9d6ba16
Files changed (2) hide show
  1. app.py +14 -3
  2. tools.py +4 -0
app.py CHANGED
@@ -21,7 +21,6 @@ from state import AgentState
21
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
 
23
  from tools import ocr_image_tool, parse_excel_tool, web_search_tool, run_tools, audio_transcriber_tool
24
- tool_node = ToolNode([ocr_image_tool, parse_excel_tool, web_search_tool, audio_transcriber_tool])
25
 
26
  llm = ChatOpenAI(model_name="gpt-4.1-mini", temperature=0.0)
27
 
@@ -121,7 +120,12 @@ def finalize_node(state: AgentState) -> AgentState:
121
  return {"final_answer": llm_response.content.strip()}
122
 
123
  # ─── 4) Wrap tools in a ToolNode ───
124
- tool_node = ToolNode([web_search_tool, ocr_image_tool, parse_excel_tool])
 
 
 
 
 
125
 
126
  # Add a node to store the previous state
127
 
@@ -149,8 +153,15 @@ graph.add_edge(START, "plan")
149
 
150
  # 5.c) plan β†’ conditional: if any tool key was set, go to "tools"; otherwise "finalize"
151
  def route_plan(plan_out: AgentState) -> str:
152
- if plan_out.get("web_search_query") or plan_out.get("ocr_path") or plan_out.get("excel_path"):
 
 
 
 
 
 
153
  return "tools"
 
154
  return "finalize"
155
 
156
  graph.add_conditional_edges(
 
21
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
22
 
23
  from tools import ocr_image_tool, parse_excel_tool, web_search_tool, run_tools, audio_transcriber_tool
 
24
 
25
  llm = ChatOpenAI(model_name="gpt-4.1-mini", temperature=0.0)
26
 
 
120
  return {"final_answer": llm_response.content.strip()}
121
 
122
  # ─── 4) Wrap tools in a ToolNode ───
123
+ tool_node = ToolNode([
124
+ web_search_tool,
125
+ ocr_image_tool,
126
+ parse_excel_tool,
127
+ audio_transcriber_tool
128
+ ])
129
 
130
  # Add a node to store the previous state
131
 
 
153
 
154
  # 5.c) plan β†’ conditional: if any tool key was set, go to "tools"; otherwise "finalize"
155
  def route_plan(plan_out: AgentState) -> str:
156
+ if (
157
+ plan_out.get("web_search_query")
158
+ or plan_out.get("ocr_path")
159
+ or plan_out.get("excel_path")
160
+ or plan_out.get("audio_path") # newly added
161
+ ):
162
+ print("Going to tools")
163
  return "tools"
164
+ print("Going to finalize")
165
  return "finalize"
166
 
167
  graph.add_conditional_edges(
tools.py CHANGED
@@ -12,6 +12,7 @@ def web_search_tool(state: AgentState) -> AgentState:
12
  Returns: {"web_search_query": None, "web_search_result": <string>}
13
  We also clear web_search_query so we don’t loop forever.
14
  """
 
15
  query = state.get("web_search_query", "")
16
  if not query:
17
  return {} # nothing to do
@@ -30,6 +31,7 @@ def ocr_image_tool(state: AgentState) -> AgentState:
30
  Expects: state["ocr_path"] is a path to an image file.
31
  Returns: {"ocr_path": None, "ocr_result": <string>}.
32
  """
 
33
  path = state.get("ocr_path", "")
34
  if not path:
35
  return {}
@@ -51,6 +53,7 @@ def parse_excel_tool(state: AgentState) -> AgentState:
51
  and state["excel_sheet_name"] optionally names a sheet.
52
  Returns: {"excel_path": None, "excel_sheet_name": None, "excel_result": <string>}.
53
  """
 
54
  path = state.get("excel_path", "")
55
  sheet = state.get("excel_sheet_name", "")
56
  if not path:
@@ -106,6 +109,7 @@ def audio_transcriber_tool(state: AgentState) -> AgentState:
106
  }
107
  If no valid audio_path is provided, returns {}.
108
  """
 
109
  path = state.get("audio_path", "")
110
  if not path or not os.path.exists(path):
111
  return {}
 
12
  Returns: {"web_search_query": None, "web_search_result": <string>}
13
  We also clear web_search_query so we don’t loop forever.
14
  """
15
+ print("reached web search tool")
16
  query = state.get("web_search_query", "")
17
  if not query:
18
  return {} # nothing to do
 
31
  Expects: state["ocr_path"] is a path to an image file.
32
  Returns: {"ocr_path": None, "ocr_result": <string>}.
33
  """
34
+ print("reached ocr image tool")
35
  path = state.get("ocr_path", "")
36
  if not path:
37
  return {}
 
53
  and state["excel_sheet_name"] optionally names a sheet.
54
  Returns: {"excel_path": None, "excel_sheet_name": None, "excel_result": <string>}.
55
  """
56
+ print("reached parse excel tool")
57
  path = state.get("excel_path", "")
58
  sheet = state.get("excel_sheet_name", "")
59
  if not path:
 
109
  }
110
  If no valid audio_path is provided, returns {}.
111
  """
112
+ print("reached audio transcriber tool")
113
  path = state.get("audio_path", "")
114
  if not path or not os.path.exists(path):
115
  return {}