Artsem Radzevich
commited on
Commit
·
056e59a
1
Parent(s):
8595b15
Fixed exec tool.
Browse files- tools/excel_analysis_tool.py +24 -10
tools/excel_analysis_tool.py
CHANGED
|
@@ -4,18 +4,29 @@ from huggingface_hub import hf_hub_download
|
|
| 4 |
|
| 5 |
class ExcelAnalysisTool(Tool):
|
| 6 |
def __init__(self):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
"Provide input as a string with the filename, e.g., 'sales_data.xlsx'."
|
| 13 |
-
),
|
| 14 |
-
inputs=["filename"]
|
| 15 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
self.repo_id = "gaia-benchmark/GAIA"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
def
|
| 19 |
"""
|
| 20 |
Loads and processes the Excel file.
|
| 21 |
|
|
@@ -25,6 +36,9 @@ class ExcelAnalysisTool(Tool):
|
|
| 25 |
Returns:
|
| 26 |
str: Total food sales in USD, or an error message.
|
| 27 |
"""
|
|
|
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
# Download the file from Hugging Face Hub
|
| 30 |
file_path = hf_hub_download(
|
|
@@ -50,4 +64,4 @@ class ExcelAnalysisTool(Tool):
|
|
| 50 |
except KeyError as e:
|
| 51 |
return f"Error: Missing expected column in the Excel file: {str(e)}"
|
| 52 |
except Exception as e:
|
| 53 |
-
return f"An unexpected error occurred: {str(e)}"
|
|
|
|
| 4 |
|
| 5 |
class ExcelAnalysisTool(Tool):
|
| 6 |
def __init__(self):
|
| 7 |
+
self.name = "ExcelAnalysisTool"
|
| 8 |
+
self.description = (
|
| 9 |
+
"Loads an Excel file from the GAIA dataset on Hugging Face and calculates "
|
| 10 |
+
"the total sales for items labeled as 'food', excluding drinks. "
|
| 11 |
+
"Provide input as a string with the filename, e.g., 'sales_data.xlsx'."
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
+
self.inputs = {
|
| 14 |
+
"filename": {
|
| 15 |
+
"type": "string",
|
| 16 |
+
"description": "The name of the Excel file to process (e.g., 'sales_data.xlsx').",
|
| 17 |
+
"nullable": True # Сделать filename необязательным
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
self.output_type = "string"
|
| 21 |
self.repo_id = "gaia-benchmark/GAIA"
|
| 22 |
+
super().__init__(
|
| 23 |
+
name=self.name,
|
| 24 |
+
description=self.description,
|
| 25 |
+
inputs=self.inputs,
|
| 26 |
+
output_type=self.output_type
|
| 27 |
+
)
|
| 28 |
|
| 29 |
+
def forward(self, filename: str = "") -> str:
|
| 30 |
"""
|
| 31 |
Loads and processes the Excel file.
|
| 32 |
|
|
|
|
| 36 |
Returns:
|
| 37 |
str: Total food sales in USD, or an error message.
|
| 38 |
"""
|
| 39 |
+
if not filename:
|
| 40 |
+
return "Error: 'filename' is required."
|
| 41 |
+
|
| 42 |
try:
|
| 43 |
# Download the file from Hugging Face Hub
|
| 44 |
file_path = hf_hub_download(
|
|
|
|
| 64 |
except KeyError as e:
|
| 65 |
return f"Error: Missing expected column in the Excel file: {str(e)}"
|
| 66 |
except Exception as e:
|
| 67 |
+
return f"An unexpected error occurred: {str(e)}"
|