Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -12,12 +14,40 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
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
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, HfApiModel
7
+ os.getenv("HF_TOKEN")
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
 
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
17
+ print("Smart Agent initialized.")
18
+
19
+ self.model = HfApiModel(
20
+ model_id="mistralai/Mistral-7B-Instruct-v0.2"
21
+ )
22
+
23
+ self.agent = ToolCallingAgent(
24
+ tools=[DuckDuckGoSearchTool()],
25
+ model=self.model,
26
+ max_steps=6,
27
+ name="gaia_agent",
28
+ description="Answers questions using web search"
29
+ )
30
+
31
+ self.agent.system_prompt = """
32
+ You are a precise question-answering agent.
33
+
34
+ Rules:
35
+ - Return ONLY the final answer
36
+ - No explanation
37
+ - No extra text
38
+ """
39
+
40
  def __call__(self, question: str) -> str:
41
+ print(f"Processing: {question[:50]}...")
42
+
43
+ result = self.agent.run(question)
44
+
45
+ # Clean answer (VERY IMPORTANT)
46
+ clean = str(result).strip().split("\n")[0]
47
+
48
+ print(f"Answer: {clean}")
49
+ return clean
50
+
51
 
52
  def run_and_submit_all( profile: gr.OAuthProfile | None):
53
  """