Spaces:
Sleeping
Sleeping
Update BasicAgent.py
Browse files- BasicAgent.py +5 -12
BasicAgent.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import smolagents, numpy, math, xlrd, os, pandas
|
2 |
from smolagents import (
|
3 |
-
|
4 |
CodeAgent,
|
5 |
HfApiModel,
|
6 |
InferenceClientModel,
|
@@ -13,22 +13,15 @@ from smolagents import (
|
|
13 |
|
14 |
#*
|
15 |
@tool
|
16 |
-
def read_excel(
|
17 |
"""
|
18 |
Read an Excel file into a pandas DataFrame.
|
19 |
-
|
20 |
-
Args:
|
21 |
-
file_path (str): Path to the Excel file.
|
22 |
-
sheet_name (str or int, optional): Sheet name or index.
|
23 |
-
|
24 |
-
Returns:
|
25 |
-
pandas.DataFrame or None
|
26 |
"""
|
|
|
27 |
try:
|
28 |
return pd.read_excel(file_path, sheet_name=sheet_name)
|
29 |
except Exception as e:
|
30 |
-
|
31 |
-
return None
|
32 |
#
|
33 |
class newAgent:
|
34 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
@@ -49,7 +42,7 @@ class newAgent:
|
|
49 |
model = HfApiModel(model_id=model_id, token=hf_token)
|
50 |
|
51 |
# include FinalAnswerTool in tools so agent knows when to stop
|
52 |
-
tools = [FinalAnswerTool(), read_excel
|
53 |
self.agent = CodeAgent(
|
54 |
tools=tools,
|
55 |
model=model,
|
|
|
1 |
import smolagents, numpy, math, xlrd, os, pandas
|
2 |
from smolagents import (
|
3 |
+
tool,
|
4 |
CodeAgent,
|
5 |
HfApiModel,
|
6 |
InferenceClientModel,
|
|
|
13 |
|
14 |
#*
|
15 |
@tool
|
16 |
+
def read_excel(file_path: str, sheet_name=0):
|
17 |
"""
|
18 |
Read an Excel file into a pandas DataFrame.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
"""
|
20 |
+
import pandas as pd
|
21 |
try:
|
22 |
return pd.read_excel(file_path, sheet_name=sheet_name)
|
23 |
except Exception as e:
|
24 |
+
return f"Error reading Excel file: {e}"
|
|
|
25 |
#
|
26 |
class newAgent:
|
27 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
|
|
42 |
model = HfApiModel(model_id=model_id, token=hf_token)
|
43 |
|
44 |
# include FinalAnswerTool in tools so agent knows when to stop
|
45 |
+
tools = [FinalAnswerTool(), read_excel]
|
46 |
self.agent = CodeAgent(
|
47 |
tools=tools,
|
48 |
model=model,
|