File size: 689 Bytes
aa84f48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from smolagents import Tool
import pandas as pd
from tabulate import tabulate

class ExcelReader(Tool):
    name = 'excel_processor'
    description = "excel reading tool, processed files of .xlsx and .xls format."
    inputs = {
        "file_path": {
            "type": "string",
            "description": "path to the excel file"
        }
    }
    output_type = "string"

    def forward(self, file_path: str) -> str:
        try:
            df = pd.read_excel(file_path)
            txt_excel = tabulate(df, headers="keys", tablefmt="github", showindex=False)
            return txt_excel
        except Exception as e:
            return f'Error in reading excel file: {str(e)}'