TSH-61 commited on
Commit
4f54374
ยท
verified ยท
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -4
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 ---
@@ -12,11 +13,44 @@ 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):
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
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):