Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,49 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
true_answer = ground_truth.get(task_id, "").strip().lower()
|
| 51 |
-
|
| 52 |
-
model_output = qa(question)[0]["generated_text"].strip().lower()
|
| 53 |
-
|
| 54 |
-
match = model_output == true_answer
|
| 55 |
-
correct += int(match)
|
| 56 |
-
|
| 57 |
-
print("\n" + "="*80)
|
| 58 |
-
print(f"QUESTION:\n{question}")
|
| 59 |
-
print(f"\nEXPECTED:\n{true_answer}")
|
| 60 |
-
print(f"\nMODEL:\n{model_output}")
|
| 61 |
-
print(f"\nMATCH: {'✅' if match else '❌'}")
|
| 62 |
-
|
| 63 |
-
print("\n" + "="*80)
|
| 64 |
-
print(f"FINAL SCORE: {correct}/20")
|
|
|
|
| 1 |
+
class BasicAgent:
|
| 2 |
+
|
| 3 |
+
def __init__(self):
|
| 4 |
+
|
| 5 |
+
print("Initializing GAIA Agent")
|
| 6 |
+
|
| 7 |
+
from smolagents import CodeAgent
|
| 8 |
+
from smolagents import DuckDuckGoSearchTool
|
| 9 |
+
from smolagents import PythonInterpreterTool
|
| 10 |
+
from smolagents import InferenceClientModel
|
| 11 |
+
|
| 12 |
+
model = InferenceClientModel(
|
| 13 |
+
model_id="meta-llama/Meta-Llama-3-8B-Instruct"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
self.agent = CodeAgent(
|
| 17 |
+
tools=[
|
| 18 |
+
DuckDuckGoSearchTool(),
|
| 19 |
+
PythonInterpreterTool()
|
| 20 |
+
],
|
| 21 |
+
model=model,
|
| 22 |
+
max_steps=6
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
def __call__(self, question: str) -> str:
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
|
| 29 |
+
print("Question:", question)
|
| 30 |
+
|
| 31 |
+
result = self.agent.run(question)
|
| 32 |
+
|
| 33 |
+
if result is None:
|
| 34 |
+
return ""
|
| 35 |
+
|
| 36 |
+
answer = str(result).strip()
|
| 37 |
+
|
| 38 |
+
# Clean answer for exact-match grading
|
| 39 |
+
answer = answer.replace("FINAL ANSWER:", "")
|
| 40 |
+
answer = answer.replace("Answer:", "")
|
| 41 |
+
answer = answer.replace("The answer is", "")
|
| 42 |
+
|
| 43 |
+
return answer.split("\n")[0].strip()
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
|
| 47 |
+
print("Agent error:", e)
|
| 48 |
+
|
| 49 |
+
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|