Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
print(f"Agent received question
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|