Download tools/excel_to_text.py from dmfelder/DF_Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/excel_to_text.py
- Command line
-
hf download hf://spaces/dmfelder/DF_Final_Assignment_Template/tools/excel_to_text.py
-
curl -L -o excel_to_text.py https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/excel_to_text.py
982 Bytes
| import pandas as pd | |
| from langchain_core.tools import tool | |
| from loguru import logger | |
| from tools.load_file import load_file | |
| def excel_to_text(path_or_url: str) -> str: | |
| """ | |
| Reads an Excel file and returns a text representation of the table data. | |
| Args: | |
| path_or_url (str): A local file path or a URL to an Excel file. | |
| Returns: | |
| str: The table contents formatted as plain text. | |
| """ | |
| 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")) |