Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 17 |
-
#
|
| 18 |
self.model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 19 |
-
|
| 20 |
-
# 2. ืืืืจืช ืืื ืืืืคืืฉ ืืจืฉืช - ืงืจืืื ืืฉืืื ืืขื ืืช ืขื ืฉืืืืช ื-GAIA
|
| 21 |
self.search_tool = DuckDuckGoSearchTool()
|
| 22 |
|
| 23 |
-
#
|
| 24 |
self.agent = CodeAgent(
|
| 25 |
tools=[self.search_tool],
|
| 26 |
model=self.model,
|
| 27 |
-
max_steps=
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
self.system_prompt_addon = (
|
| 32 |
-
"\
|
| 33 |
-
"
|
| 34 |
-
"Do NOT
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
def __call__(self, question: str) -> str:
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return final_answer
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
-
print(f"Error during agent
|
| 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 |
"""
|