SamarthPujari commited on
Commit
8796502
·
verified ·
1 Parent(s): 8b5ae06

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +22 -23
Gradio_UI.py CHANGED
@@ -11,29 +11,28 @@ class GradioUI:
11
  self.search_tool = None
12
  self.doc_qa_tool = None
13
 
14
- # Map tools by known types or names
15
- for tool in self.agent.tools:
16
- try:
17
- tool_name = getattr(tool, "__name__", None)
18
- if tool_name == "get_current_time_in_timezone":
19
- self.get_time_tool = tool
20
- elif tool_name == "get_current_weather":
21
- self.get_weather_tool = tool
22
- elif tool_name == "document_qna_tool":
23
- self.doc_qa_tool = tool
24
- elif "text-to-image" in str(tool):
25
- self.image_gen_tool = tool
26
- elif "DuckDuckGoSearchTool" in str(tool):
27
- self.search_tool = tool
28
- except Exception:
29
- pass
30
-
31
- # Fallback in case mapping fails
32
- self.get_time_tool = self.get_time_tool or self.agent.tools[0]
33
- self.get_weather_tool = self.get_weather_tool or self.agent.tools[1]
34
- self.image_gen_tool = self.image_gen_tool or self.agent.tools[2]
35
- self.search_tool = self.search_tool or self.agent.tools[3]
36
- self.doc_qa_tool = self.doc_qa_tool or self.agent.tools[4]
37
 
38
  def launch(self):
39
  with gr.Blocks() as demo:
 
11
  self.search_tool = None
12
  self.doc_qa_tool = None
13
 
14
+ # Try to detect tool types from dictionary-like access
15
+ tools = getattr(agent, "tools", {})
16
+
17
+ for tool in tools.values(): # Use `.values()` instead of indexing
18
+ tool_name = getattr(tool, "__name__", None)
19
+ if tool_name == "get_current_time_in_timezone":
20
+ self.get_time_tool = tool
21
+ elif tool_name == "get_current_weather":
22
+ self.get_weather_tool = tool
23
+ elif tool_name == "document_qna_tool":
24
+ self.doc_qa_tool = tool
25
+ elif "text-to-image" in str(tool):
26
+ self.image_gen_tool = tool
27
+ elif "DuckDuckGoSearchTool" in str(tool):
28
+ self.search_tool = tool
29
+
30
+ # Optional fallback with warnings
31
+ assert self.get_time_tool, "Missing: get_current_time_in_timezone"
32
+ assert self.get_weather_tool, "Missing: get_current_weather"
33
+ assert self.doc_qa_tool, "Missing: document_qna_tool"
34
+ assert self.image_gen_tool, "Missing: image generation tool"
35
+ assert self.search_tool, "Missing: search tool"
 
36
 
37
  def launch(self):
38
  with gr.Blocks() as demo: