Spaces:
Sleeping
Sleeping
Update BasicAgent.py
Browse files- BasicAgent.py +7 -37
BasicAgent.py
CHANGED
@@ -14,37 +14,6 @@ from smolagents import (
|
|
14 |
)
|
15 |
|
16 |
#*
|
17 |
-
@tool
|
18 |
-
def analyze_excel_file(file_path: str, query: str) -> str:
|
19 |
-
"""
|
20 |
-
Analyze an Excel file using pandas and answer a question about it.
|
21 |
-
|
22 |
-
Args:
|
23 |
-
file_path: Path to the Excel file
|
24 |
-
query: Question about the data
|
25 |
-
|
26 |
-
Returns:
|
27 |
-
Analysis result or error message
|
28 |
-
"""
|
29 |
-
try:
|
30 |
-
import pandas as pd
|
31 |
-
|
32 |
-
# Read the Excel file
|
33 |
-
df = pd.read_excel(file_path)
|
34 |
-
|
35 |
-
# Run various analyses based on the query
|
36 |
-
result = f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
37 |
-
result += f"Columns: {', '.join(df.columns)}\n\n"
|
38 |
-
|
39 |
-
# Add summary statistics
|
40 |
-
result += "Summary statistics:\n"
|
41 |
-
result += str(df.describe())
|
42 |
-
|
43 |
-
return result
|
44 |
-
except ImportError:
|
45 |
-
return "Error: pandas and openpyxl are not installed. Please install them with 'pip install pandas openpyxl'."
|
46 |
-
except Exception as e:
|
47 |
-
return f"Error analyzing Excel file: {str(e)}"
|
48 |
|
49 |
#
|
50 |
class newAgent:
|
@@ -56,17 +25,18 @@ class newAgent:
|
|
56 |
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
|
57 |
#*
|
58 |
system_prompt=(
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
64 |
)
|
65 |
#*
|
66 |
model = HfApiModel(model_id=model_id, token=hf_token)
|
67 |
|
68 |
# include FinalAnswerTool in tools so agent knows when to stop
|
69 |
-
tools = [FinalAnswerTool()
|
70 |
self.agent = CodeAgent(
|
71 |
tools=tools,
|
72 |
model=model,
|
|
|
14 |
)
|
15 |
|
16 |
#*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
#
|
19 |
class newAgent:
|
|
|
25 |
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
|
26 |
#*
|
27 |
system_prompt=(
|
28 |
+
"You are an agent that answers exam questions. "
|
29 |
+
"Your answers should contain only what is asked for in the question, without any other content. "
|
30 |
+
"Be exact and concise in your answers. "
|
31 |
+
"Avoid adding explanations or additional information unless explicitly requested. "
|
32 |
+
"If asked for a list, provide ONLY the items requested separated by commas."
|
33 |
+
|
34 |
)
|
35 |
#*
|
36 |
model = HfApiModel(model_id=model_id, token=hf_token)
|
37 |
|
38 |
# include FinalAnswerTool in tools so agent knows when to stop
|
39 |
+
tools = [FinalAnswerTool()]
|
40 |
self.agent = CodeAgent(
|
41 |
tools=tools,
|
42 |
model=model,
|