File size: 1,798 Bytes
6073dc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pandas as pd
from huggingface_hub import hf_hub_download

class ExcelAnalysisTool:
    def __init__(self):
        self.name = "ExcelAnalysisTool"
        self.description = (
            "Loads an Excel file from the GAIA dataset on Hugging Face and calculates "
            "the total sales for items labeled as 'food', excluding drinks. "
            "Provide input as a string with the filename, e.g., 'sales_data.xlsx'."
        )
        self.repo_id = "gaia-benchmark/GAIA"

    def __call__(self, filename: str) -> str:
        """

        Loads and processes the Excel file.



        Args:

            filename (str): The name of the Excel file (e.g., 'sales_data.xlsx').



        Returns:

            str: Total food sales in USD, or an error message.

        """
        try:
            # Download the file from Hugging Face Hub
            file_path = hf_hub_download(
                repo_id=self.repo_id,
                filename=filename,
                repo_type="dataset"
            )

            # Load the Excel file into a DataFrame
            df = pd.read_excel(file_path)

            # Filter rows: category == 'food' and item != 'drinks'
            food_sales = df[
                (df['category'].str.lower() == 'food') &
                (df['item'].str.lower() != 'drinks')
            ]

            total_sales = food_sales['sales'].sum()
            return f"Total sales for food items: ${total_sales:.2f}"

        except FileNotFoundError:
            return "Error: The specified file was not found."
        except KeyError as e:
            return f"Error: Missing expected column in the Excel file: {str(e)}"
        except Exception as e:
            return f"An unexpected error occurred: {str(e)}"