Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| import pandas as pd | |
| from smolagents import tool | |
| HF_AGENTS_API_URL = "https://agents-course-unit4-scoring.hf.space" | |
| api_key = os.environ.get("hf_token") | |
| def multiply(a: int, b: int) -> int: | |
| """Multiply two numbers. | |
| Args: | |
| a: first real number | |
| b: second real number | |
| """ | |
| return a * b | |
| def add(a: int, b: int) -> int: | |
| """Add two numbers. | |
| Args: | |
| a: first real number | |
| b: second real number | |
| """ | |
| return a + b | |
| def subtract(a: int, b: int) -> int: | |
| """Subtract two numbers. | |
| Args: | |
| a: first real number | |
| b: second real number | |
| """ | |
| return a - b | |
| def divide(a: int, b: int) -> int: | |
| """Divide two numbers. | |
| Args: | |
| a: first real number | |
| b: second real number | |
| """ | |
| if b == 0: | |
| raise ValueError("Cannot divide by zero.") | |
| return a / b | |
| def modulus(a: int, b: int) -> int: | |
| """Get the modulus of two numbers. | |
| Args: | |
| a: first real number | |
| b: second real number | |
| """ | |
| return a % b | |
| def task_file_downloader(task_id: str, file_path: str) -> None: | |
| """ | |
| Download the file from the task id and save it to the file path. | |
| Args: | |
| task_id: The id of the task to download the file from. | |
| file_path: The full path to save the file to. | |
| """ | |
| response = requests.get(f"{HF_AGENTS_API_URL}/files/{task_id}").content | |
| with open(file_path, "wb") as f: | |
| f.write(response) | |
| def read_excel_tool(excel_file:str)->str: | |
| """ | |
| This tool is used to read the Excel file using pandas library | |
| Args: | |
| excel_file: the location or file name of the Excel | |
| """ | |
| try: | |
| data_frame = pd.read_excel(excel_file) | |
| str_df = data_frame.to_string() | |
| return str_df | |
| except FileNotFoundError as e: | |
| return f'Error occurred during tool usage{e}' | |