import pandas as pd from langchain_core.tools import tool from loguru import logger from tools.load_file import load_file @tool("excel_to_text_tool", parse_docstring=True) def excel_to_text(path_or_url: str) -> str: """ Read an Excel file and return a text representation of the table data. Args: path_or_url (str): Either a local file path to an Excel file or a URL pointing to an Excel file. Returns: str: Text representation of the table data """ logger.info(f"use excel_to_text with param: {path_or_url}") try: excel = load_file(path_or_url) df = pd.read_excel(excel) return df.to_markdown(index=False) except Exception as e: return f"Error reading Excel file: {str(e)}" if __name__ == "__main__": print(excel_to_text.invoke("../data/7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx")) print( excel_to_text.invoke("https://agents-course-unit4-scoring.hf.space/files/7bd855d8-463d-4ed5-93ca-5fe35145f733"))