Spaces:
Sleeping
Sleeping
geadmin
commited on
Commit
·
8302172
1
Parent(s):
b01bb7f
update with codeAgent
Browse files
app.py
CHANGED
@@ -3,8 +3,7 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
-
from smolagents import
|
7 |
-
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
@@ -15,17 +14,15 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
15 |
class BasicAgent:
|
16 |
def __init__(self):
|
17 |
print("BasicAgent initialized.")
|
18 |
-
self.agent =
|
19 |
-
|
20 |
-
model = HfApiModel,
|
21 |
-
)
|
22 |
def __call__(self, question: str) -> str:
|
23 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
24 |
# fixed_answer = "This is a default answer."
|
25 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
26 |
# return fixed_answer
|
27 |
try:
|
28 |
-
result = self.agent(question)
|
29 |
print(f"Agent answer: {result}")
|
30 |
return result
|
31 |
except Exception as e:
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
|
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
|
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
print("BasicAgent initialized.")
|
17 |
+
self.agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
|
18 |
+
|
|
|
|
|
19 |
def __call__(self, question: str) -> str:
|
20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
21 |
# fixed_answer = "This is a default answer."
|
22 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
23 |
# return fixed_answer
|
24 |
try:
|
25 |
+
result = self.agent.run(question)
|
26 |
print(f"Agent answer: {result}")
|
27 |
return result
|
28 |
except Exception as e:
|