petrov826 commited on
Commit
6fed45e
·
verified ·
1 Parent(s): 7d0f3e4

allow agents to access files and add a tool to process audio files

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -11,7 +11,8 @@ from smolagents import (
11
  DuckDuckGoSearchTool,
12
  VisitWebpageTool,
13
  GoogleSearchTool,
14
- WikipediaSearchTool
 
15
  )
16
 
17
  from rate_limiter import RateLimiter
@@ -37,16 +38,17 @@ class BasicAgent:
37
  VisitWebpageTool(),
38
  GoogleSearchTool(provider="serper"),
39
  WikipediaSearchTool(),
40
- YoutubeTranscriptTool()
 
41
  ],
42
  model=model,
43
  step_callbacks=[rate_limiter.increment_and_sleep_if_needed],
44
  )
45
  print("BasicAgent initialized.")
46
 
47
- def __call__(self, question: str) -> str:
48
  print(f"Agent received question (first 50 chars): {question[:50]}...")
49
- answer = self.agent.run(question)
50
  print(f"Agent returning answer: {answer}")
51
  return answer
52
 
@@ -107,11 +109,20 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
107
  for item in questions_data:
108
  task_id = item.get("task_id")
109
  question_text = item.get("question")
 
 
 
 
 
 
 
 
 
110
  if not task_id or question_text is None:
111
  print(f"Skipping item with missing task_id or question: {item}")
112
  continue
113
  try:
114
- submitted_answer = agent(question_text)
115
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
116
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
117
  except Exception as e:
 
11
  DuckDuckGoSearchTool,
12
  VisitWebpageTool,
13
  GoogleSearchTool,
14
+ WikipediaSearchTool,
15
+ SpeechToTextTool
16
  )
17
 
18
  from rate_limiter import RateLimiter
 
38
  VisitWebpageTool(),
39
  GoogleSearchTool(provider="serper"),
40
  WikipediaSearchTool(),
41
+ YoutubeTranscriptTool(),
42
+ SpeechToTextTool()
43
  ],
44
  model=model,
45
  step_callbacks=[rate_limiter.increment_and_sleep_if_needed],
46
  )
47
  print("BasicAgent initialized.")
48
 
49
+ def __call__(self, question: str, additional_args: dict = {}) -> str:
50
  print(f"Agent received question (first 50 chars): {question[:50]}...")
51
+ answer = self.agent.run(question, additional_args)
52
  print(f"Agent returning answer: {answer}")
53
  return answer
54
 
 
109
  for item in questions_data:
110
  task_id = item.get("task_id")
111
  question_text = item.get("question")
112
+
113
+ file_name_to_url = {}
114
+
115
+ if item.get("file_name"):
116
+ file_name = item.get("file_name")
117
+ file_url = f"{api_url}/files/{task_id}"
118
+
119
+ file_name_to_url = {file_name: file_url}
120
+
121
  if not task_id or question_text is None:
122
  print(f"Skipping item with missing task_id or question: {item}")
123
  continue
124
  try:
125
+ submitted_answer = agent(question_text, file_name_to_url)
126
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
127
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
128
  except Exception as e: