Spaces:
Sleeping
Sleeping
File size: 1,205 Bytes
f66d8b7 72846b4 f66d8b7 c976573 f66d8b7 aa1410a c976573 f66d8b7 |
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 |
from utils import clean_text
from langchain_core.tools import tool
import io
import pandas as pd
import base64
from utils import get_base64, get_text_file_contents
@tool
def parse_excel(base64_filepath: str) -> str:
"""Parses a base64-encoded Excel (.xlsx) file and returns a markdown summary."""
try:
base64_str = get_text_file_contents(base64_filepath)
file_bytes = base64.b64decode(base64_str)
excel_file = pd.ExcelFile(io.BytesIO(file_bytes))
output = []
for sheet in excel_file.sheet_names:
df = excel_file.parse(sheet)
output.append(f"### Sheet: {sheet}\n")
output.append(df.head(20).to_markdown(index=False))
output.append("\n")
return "\n".join(output)
except Exception as e:
return f"Error parsing Excel file: {e}"
if __name__ == "__main__":
import sys
filepath = 'C:\\Users\\agazo\\Downloads\\7bd855d8-463d-4ed5-93ca-5fe35145f733_file.xlsx'
try:
result = parse_excel(get_base64(filepath))
print(result)
except FileNotFoundError:
print(f"File not found: {filepath}")
except Exception as e:
print(f"Error: {e}") |