Spaces:
Sleeping
Sleeping
Update BasicAgent.py
Browse files- BasicAgent.py +27 -7
BasicAgent.py
CHANGED
@@ -15,17 +15,37 @@ from smolagents import (
|
|
15 |
|
16 |
#*
|
17 |
@tool
|
18 |
-
def
|
19 |
"""
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
"""
|
22 |
try:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
except Exception as e:
|
28 |
-
return f"Error
|
|
|
29 |
#
|
30 |
class newAgent:
|
31 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
|
|
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:
|
51 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|