Yago Bolivar commited on
Commit
17e76f4
·
1 Parent(s): 4285cbd

refactor: update tool imports and instantiations for consistency; enhance Gradio UI error handling

Browse files
Files changed (1) hide show
  1. app.py +20 -30
app.py CHANGED
@@ -6,11 +6,9 @@ from src.final_answer_tool import FinalAnswerTool
6
  from src.web_browsing_tool import WebBrowser
7
  from src.file_processing_tool import FileIdentifier
8
  from src.image_processing_tool import ImageProcessor
9
- # src.markdown_table_parser.py contains a function, will need a wrapper Tool class
10
- # from src.markdown_table_parser import parse_markdown_table
11
  from src.python_tool import CodeExecutionTool
12
- # src.speech_to_text.py contains a function, will need a wrapper Tool class
13
- # from src.speech_to_text import transcribe_audio
14
  from src.spreadsheet_tool import SpreadsheetTool
15
  from src.text_reversal_tool import TextReversalTool
16
  from src.video_processing_tool import VideoProcessingTool
@@ -27,25 +25,16 @@ model = HfApiModel(
27
  )
28
 
29
  # Instantiate Tools
30
- # These instantiations assume the classes are now proper smolagents Tools
31
  final_answer_tool = FinalAnswerTool()
32
  web_browsing_tool = WebBrowser()
33
  file_processing_tool = FileIdentifier()
34
  image_processing_tool = ImageProcessor()
 
35
  python_tool = CodeExecutionTool()
 
36
  spreadsheet_tool = SpreadsheetTool()
37
  text_reversal_tool = TextReversalTool()
38
  video_processing_tool = VideoProcessingTool()
39
- ddg_search_tool = DuckDuckGoSearchTool()
40
-
41
- # For functions that need to be wrapped as tools (e.g., markdown_table_parser, speech_to_text):
42
- # These would need wrapper classes defined, potentially in their respective files or here.
43
- # Example (conceptual):
44
- # from src.markdown_table_parser import MarkdownTableParserTool # Assuming this wrapper exists
45
- # markdown_parser_tool = MarkdownTableParserTool()
46
- # from src.speech_to_text import SpeechToTextTool # Assuming this wrapper exists
47
- # speech_to_text_tool = SpeechToTextTool()
48
-
49
 
50
  # Load Prompts
51
  try:
@@ -60,29 +49,24 @@ except yaml.YAMLError as e:
60
 
61
 
62
  # Create the Agent
63
- # Note: Tools that are not yet proper smolagent tools (or their wrappers) are commented out.
64
- # They need to be converted/wrapped first and then added to this list.
65
  agent_tools = [
66
  final_answer_tool,
67
  web_browsing_tool,
68
  file_processing_tool,
69
  image_processing_tool,
70
- # markdown_parser_tool, # Add when MarkdownTableParserTool wrapper is ready
71
  python_tool,
72
- # speech_to_text_tool, # Add when SpeechToTextTool wrapper is ready
73
  spreadsheet_tool,
74
  text_reversal_tool,
75
- video_processing_tool,
76
- ddg_search_tool
77
  ]
78
 
79
  agent = CodeAgent(
80
  model=model,
81
  tools=agent_tools,
82
- max_steps=15, # Increased max_steps for potentially complex questions
83
- verbosity_level=1, # 0 for less, 1 for normal, 2 for more verbose
84
- # grammar=None, # Specify if you have a grammar for model output
85
- # planning_interval=None, # Steps between planning phases
86
  name="ComprehensiveQuestionAgent",
87
  description="An agent equipped with a suite of tools to answer diverse questions from the common_questions.json set.",
88
  prompt_templates=prompt_templates
@@ -91,12 +75,18 @@ agent = CodeAgent(
91
  # Launch the Gradio UI
92
  if __name__ == '__main__':
93
  print("Launching Gradio UI...")
94
- # Ensure GradioUI can accept the agent instance
95
- # If GradioUI is not designed to take an agent directly, this might need adjustment
96
- # based on how GradioUI is implemented.
97
  try:
98
  ui = GradioUI(agent)
99
  ui.launch()
100
  except Exception as e:
101
- print(f"Error launching Gradio UI: {e}")
102
- print("Please ensure GradioUI is correctly defined and can be initialized with the agent.")
 
 
 
 
 
 
 
 
 
 
6
  from src.web_browsing_tool import WebBrowser
7
  from src.file_processing_tool import FileIdentifier
8
  from src.image_processing_tool import ImageProcessor
9
+ from src.markdown_table_parser import MarkdownTableParserTool # Updated
 
10
  from src.python_tool import CodeExecutionTool
11
+ from src.speech_to_text import SpeechToTextTool # Updated
 
12
  from src.spreadsheet_tool import SpreadsheetTool
13
  from src.text_reversal_tool import TextReversalTool
14
  from src.video_processing_tool import VideoProcessingTool
 
25
  )
26
 
27
  # Instantiate Tools
 
28
  final_answer_tool = FinalAnswerTool()
29
  web_browsing_tool = WebBrowser()
30
  file_processing_tool = FileIdentifier()
31
  image_processing_tool = ImageProcessor()
32
+ markdown_parser_tool = MarkdownTableParserTool() # Updated
33
  python_tool = CodeExecutionTool()
34
+ speech_to_text_tool = SpeechToTextTool() # Updated
35
  spreadsheet_tool = SpreadsheetTool()
36
  text_reversal_tool = TextReversalTool()
37
  video_processing_tool = VideoProcessingTool()
 
 
 
 
 
 
 
 
 
 
38
 
39
  # Load Prompts
40
  try:
 
49
 
50
 
51
  # Create the Agent
 
 
52
  agent_tools = [
53
  final_answer_tool,
54
  web_browsing_tool,
55
  file_processing_tool,
56
  image_processing_tool,
57
+ markdown_parser_tool, # Updated
58
  python_tool,
59
+ speech_to_text_tool, # Updated
60
  spreadsheet_tool,
61
  text_reversal_tool,
62
+ video_processing_tool
 
63
  ]
64
 
65
  agent = CodeAgent(
66
  model=model,
67
  tools=agent_tools,
68
+ max_steps=15,
69
+ verbosity_level=1,
 
 
70
  name="ComprehensiveQuestionAgent",
71
  description="An agent equipped with a suite of tools to answer diverse questions from the common_questions.json set.",
72
  prompt_templates=prompt_templates
 
75
  # Launch the Gradio UI
76
  if __name__ == '__main__':
77
  print("Launching Gradio UI...")
 
 
 
78
  try:
79
  ui = GradioUI(agent)
80
  ui.launch()
81
  except Exception as e:
82
+ print(f"Failed to launch Gradio UI: {e}")
83
+ print("Attempting to run agent with a sample query directly...")
84
+ try:
85
+ # This is a placeholder for a direct test if Gradio fails.
86
+ # You might want to load a question from common_questions.json here.
87
+ sample_query = "What is the capital of France and reverse the answer?"
88
+ print(f"Testing agent with query: {sample_query}")
89
+ response = agent.run(sample_query)
90
+ print(f"Agent response: {response}")
91
+ except Exception as agent_e:
92
+ print(f"Error running agent directly: {agent_e}")