optionEdge commited on
Commit
062f80b
·
verified ·
1 Parent(s): a1d1bf7

Update BasicAgent.py

Browse files
Files changed (1) hide show
  1. BasicAgent.py +27 -7
BasicAgent.py CHANGED
@@ -15,17 +15,37 @@ from smolagents import (
15
 
16
  #*
17
  @tool
18
- def read_excel(file_path: str, sheet_name: str = "0") -> str:
19
  """
20
- Read an Excel file and return it as JSON-like string.
 
 
 
 
 
 
 
21
  """
22
  try:
23
- # Try to convert sheet_name to int if it's a number
24
- sheet = int(sheet_name) if sheet_name.isdigit() else sheet_name
25
- df = pd.read_excel(file_path, sheet_name=sheet)
26
- return df.to_json(orient="records")
 
 
 
 
 
 
 
 
 
 
 
 
27
  except Exception as e:
28
- return f"Error reading Excel file: {e}"
 
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."""