salihaipts commited on
Commit
ca340f8
·
verified ·
1 Parent(s): 81917a3

update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -19,6 +20,25 @@ class BasicAgent:
19
  print(f"Agent returning fixed answer: {fixed_answer}")
20
  return fixed_answer
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
24
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -80,7 +100,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
80
  print(f"Skipping item with missing task_id or question: {item}")
81
  continue
82
  try:
83
- submitted_answer = agent(question_text)
84
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
85
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
86
  except Exception as e:
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, Tool, tool, VisitWebpageTool
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
20
  print(f"Agent returning fixed answer: {fixed_answer}")
21
  return fixed_answer
22
 
23
+ def simple_agent(question):
24
+
25
+ agent = CodeAgent(
26
+ tools=[
27
+ DuckDuckGoSearchTool(),
28
+ VisitWebpageTool(),
29
+ FinalAnswerTool()
30
+ ],
31
+ model=InferenceClientModel(),
32
+ max_steps=10,
33
+ verbosity_level=2
34
+ )
35
+
36
+ prompt = f"You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. Question: {question}"
37
+
38
+ answer = agent.run(prompt)
39
+
40
+ return answer
41
+
42
  def run_and_submit_all( profile: gr.OAuthProfile | None):
43
  """
44
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
100
  print(f"Skipping item with missing task_id or question: {item}")
101
  continue
102
  try:
103
+ submitted_answer = simple_agent(question_text)
104
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
105
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
106
  except Exception as e: