File size: 1,289 Bytes
8b3139e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
from smolagents import Tool
import requests
import pandas as pd
from io import BytesIO
from typing import Any

#AUTHORIZED_TYPES = [
#    "string",
#    "boolean",
#    "integer",
#    "number",
#    "image",
#    "audio",
#    "array",
#    "object",
#    "any",
#    "null",
#]


class ExcelLoadTool(Tool):
    name = "_my_tool_excel_load"
    description = """
        Load Excel spreadsheet for the provided task id
        To invoke the tool use code as below
        <code>
        contents = _my_tool_excel_load(task_id="dummy")
        </code>
    """

    inputs = {
        "task_id": {
            "type": "string",
            "description": "task id to load excel file",
        }
    }

    output_type = "any"
    api_url = "https://agents-course-unit4-scoring.hf.space"

    def forward(self, task_id: str) -> Any:
        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
        }
        url = f"{self.api_url}/files/{task_id}"
        response = requests.get(url, headers=headers)
        bt = BytesIO(response.content)
        df = pd.read_excel(bt)
        #print(f"***KS*** Loaded Excel file contents for \n\ttask id: {task_id} \n\timage: {df}")
        return df