TSH-61 commited on
Commit
3e32f37
ยท
verified ยท
1 Parent(s): 9f3d97b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -13,45 +13,58 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  class BasicAgent:
15
  def __init__(self):
16
- print("Initializing smart smolagent...")
17
- # 1. ื”ื’ื“ืจืช ืžื•ื“ืœ ื”ืฉืคื” - ืžืฉืชืžืฉื™ื ื‘ืžื•ื“ืœ ื—ื–ืง ื•ื—ื™ื ืžื™ ืฉืœ Hugging Face (ืื• ืžื•ื“ืœ ืื—ืจ ืœื‘ื—ื™ืจืชืš)
18
  self.model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
19
-
20
- # 2. ื”ื’ื“ืจืช ื›ืœื™ ื”ื—ื™ืคื•ืฉ ื‘ืจืฉืช - ืงืจื™ื˜ื™ ื‘ืฉื‘ื™ืœ ืœืขื ื•ืช ืขืœ ืฉืืœื•ืช ื”-GAIA
21
  self.search_tool = DuckDuckGoSearchTool()
22
 
23
- # 3. ื™ืฆื™ืจืช ืกื•ื›ืŸ ืžื‘ื•ืกืก ืงื•ื“ (CodeAgent) ืฉื™ื•ื“ืข ืœื›ืชื•ื‘ ืคื™ื™ืชื•ืŸ ื›ื“ื™ ืœืคืชื•ืจ ื‘ืขื™ื•ืช
24
  self.agent = CodeAgent(
25
  tools=[self.search_tool],
26
  model=self.model,
27
- max_steps=6 # ื ื•ืชืŸ ืœื• ืžืกืคื™ืง ืฉืœื‘ื™ื ืœืคืชื•ืจ ืžืฉื™ืžื•ืช ืžื•ืจื›ื‘ื•ืช
28
  )
29
 
30
- # 4. ื”ื ื—ื™ื™ืช ืžืขืจื›ืช (System Prompt) ืงืฉื•ื—ื” ื›ื“ื™ ืฉื™ื—ื–ื™ืจ ืืš ื•ืจืง ืืช ื”ืชืฉื•ื‘ื” ื”ืกื•ืคื™ืช
31
  self.system_prompt_addon = (
32
- "\nCRITICAL: Your final answer must be extremely concise. "
33
- "Return ONLY the plain value (e.g., a number, a single word, or a comma-separated list). "
34
- "Do NOT include any explanatory text, markdown formatting like 'FINAL ANSWER:', or units."
 
 
 
35
  )
36
 
37
  def __call__(self, question: str) -> str:
38
- print(f"Agent received question: {question[:100]}...")
 
 
 
 
 
 
 
 
 
 
 
39
  try:
40
- # ื”ื•ืกืคืช ื”ื”ื ื—ื™ื” ื”ืžื“ื•ื™ืงืช ืœืฉืืœื”
41
- full_query = question + self.system_prompt_addon
42
-
43
  # ื”ืจืฆืช ื”ืกื•ื›ืŸ
44
  raw_response = self.agent.run(full_query)
45
 
46
- # ื ื™ืงื•ื™ ื‘ืกื™ืกื™ ืฉืœ ื”ืชืฉื•ื‘ื” ืžืจื•ื•ื—ื™ื ืžื™ื•ืชืจื™ื
47
- final_answer = str(raw_response).strip()
48
- print(f"Agent generated answer: {final_answer}")
 
 
 
 
 
49
  return final_answer
50
 
51
  except Exception as e:
52
- print(f"Error during agent execution: {e}")
53
  return "Error"
54
- return fixed_answer
55
 
56
  def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  """
 
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  class BasicAgent:
15
  def __init__(self):
16
+ print("Initializing Advanced GAIA Agent...")
17
+ # ืžื•ื“ืœ ื—ื–ืง ืฉืžืชืื™ื ืœืžืฉื™ืžื•ืช ืงื•ื“ ื•ื—ื™ืคื•ืฉ
18
  self.model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
 
 
19
  self.search_tool = DuckDuckGoSearchTool()
20
 
21
+ # ื‘ื ื™ื™ืช ื”ืกื•ื›ืŸ
22
  self.agent = CodeAgent(
23
  tools=[self.search_tool],
24
  model=self.model,
25
+ max_steps=7
26
  )
27
 
28
+ # ื”ื ื—ื™ื” ืฉืžื‘ื”ื™ืจื” ื‘ืฆื•ืจื” ื—ื“ ืžืฉืžืขื™ืช ืื™ืš ืœื”ื—ื–ื™ืจ ืืช ื”ืชืฉื•ื‘ื”
29
  self.system_prompt_addon = (
30
+ "\n\n[CRITICAL INSTRUCTION]\n"
31
+ "You must output ONLY the final raw answer string or number. "
32
+ "Do NOT write 'The answer is...', do NOT include markdown formatting, "
33
+ "do NOT include units (like $, %, or USD) unless explicitly asked for the unit name, "
34
+ "and do NOT explain your reasoning in the final output. "
35
+ "Just output the exact value so an exact-string-match script can validate it."
36
  )
37
 
38
  def __call__(self, question: str) -> str:
39
+ # ืื ื—ื ื• ืฆืจื™ื›ื™ื ืœื’ืฉืช ืœ-task_id, ื ื ืกื” ืœื—ืœืฅ ืื•ืชื• ืžืชื•ืš ื”ืœื•ื’ ืฉืœ ื”ืจื™ืฆื” ืื• ืฉื ื—ืคืฉ ืงื‘ืฆื™ื ื–ืžื™ื ื™ื.
40
+ # ื‘ืฉื‘ื™ืœ ื”ืคืฉื˜ื•ืช, ื ื ื—ื” ืืช ื”ืกื•ื›ืŸ ืœื‘ื“ื•ืง ืื ื™ืฉ ืงื‘ืฆื™ื ืฉื”ื•ืจื“ื• ื‘ืชื™ืงื™ื™ืช ื”ืขื‘ื•ื“ื” ืฉืœื•.
41
+
42
+ print(f"\n--- Processing New Task ---")
43
+ print(f"Question: {question[:150]}...")
44
+
45
+ # ื ื‘ื“ื•ืง ืื™ืœื• ืงื‘ืฆื™ื ืงื™ื™ืžื™ื ื‘ืชื™ืงื™ื™ื” ื”ื ื•ื›ื—ื™ืช ื›ื“ื™ ืฉื”ืกื•ื›ืŸ ื™ื“ืข ืื ื™ืฉ ืœื• ืงื•ื‘ืฅ ืืงืกืœ ืื• ืชืžื•ื ื” ืœืขื‘ื•ื“ ืื™ืชื
46
+ current_files = [f for f in os.listdir('.') if os.path.isfile(f)]
47
+ files_context = f"\nAvailable files in your local directory that might be related to this task: {current_files}"
48
+
49
+ full_query = question + files_context + self.system_prompt_addon
50
+
51
  try:
 
 
 
52
  # ื”ืจืฆืช ื”ืกื•ื›ืŸ
53
  raw_response = self.agent.run(full_query)
54
 
55
+ # ื ื™ืงื•ื™ ืื’ืจืกื™ื‘ื™ ืฉืœ ื”ืชืฉื•ื‘ื” ืžืกื™ืžื ื™ื ืžื™ื•ืชืจื™ื
56
+ final_answer = str(raw_response).strip().replace('"', '').replace("'", "")
57
+
58
+ # ืื ื”ื•ื ื”ื—ื–ื™ืจ ืžืฉืคื˜ ืืจื•ืš ื‘ื˜ืขื•ืช, ื ื ืกื” ืœืงื—ืช ืจืง ืืช ื”ืžื™ืœื”/ืžืกืคืจ ื”ืื—ืจื•ืŸ ืื• ืœื ืงื•ืช ื ืงื•ื“ื” ื‘ืกื•ืฃ
59
+ if final_answer.endswith('.'):
60
+ final_answer = final_answer[:-1]
61
+
62
+ print(f"=> Final Cleaned Answer: '{final_answer}'")
63
  return final_answer
64
 
65
  except Exception as e:
66
+ print(f"Error during agent run: {e}")
67
  return "Error"
 
68
 
69
  def run_and_submit_all( profile: gr.OAuthProfile | None):
70
  """