Spaces:
Sleeping
Sleeping
Pycrolis
commited on
Commit
·
f3b4b95
1
Parent(s):
604617b
feat(tool): add excel_to_text tool for converting Excel data to text
Browse files- ShrewdAgent.py +3 -1
- tools/excel_to_text.py +32 -0
ShrewdAgent.py
CHANGED
@@ -13,6 +13,7 @@ from langgraph.pregel import PregelProtocol
|
|
13 |
from loguru import logger
|
14 |
from pydantic import SecretStr
|
15 |
|
|
|
16 |
from tools.produce_classifier import produce_classifier
|
17 |
from tools.sort_words_alphabetically import sort_words_alphabetically
|
18 |
from tools.web_page_information_extractor import web_page_information_extractor
|
@@ -45,7 +46,8 @@ class ShrewdAgent:
|
|
45 |
web_page_information_extractor,
|
46 |
youtube_transcript,
|
47 |
produce_classifier,
|
48 |
-
sort_words_alphabetically
|
|
|
49 |
]
|
50 |
self.llm = ChatOpenAI(
|
51 |
model="gpt-4o-mini",
|
|
|
13 |
from loguru import logger
|
14 |
from pydantic import SecretStr
|
15 |
|
16 |
+
from tools.excel_to_text import excel_to_text
|
17 |
from tools.produce_classifier import produce_classifier
|
18 |
from tools.sort_words_alphabetically import sort_words_alphabetically
|
19 |
from tools.web_page_information_extractor import web_page_information_extractor
|
|
|
46 |
web_page_information_extractor,
|
47 |
youtube_transcript,
|
48 |
produce_classifier,
|
49 |
+
sort_words_alphabetically,
|
50 |
+
excel_to_text,
|
51 |
]
|
52 |
self.llm = ChatOpenAI(
|
53 |
model="gpt-4o-mini",
|
tools/excel_to_text.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from langchain_core.tools import tool
|
3 |
+
from loguru import logger
|
4 |
+
|
5 |
+
from tools.load_file import load_file
|
6 |
+
|
7 |
+
|
8 |
+
@tool("excel_to_text_tool", parse_docstring=True)
|
9 |
+
def excel_to_text(path_or_url: str) -> str:
|
10 |
+
"""
|
11 |
+
Read an Excel file and return a text representation of the table data.
|
12 |
+
|
13 |
+
Args:
|
14 |
+
path_or_url (str): Either a local file path to an Excel file or a URL pointing to an Excel file.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
str: Text representation of the table data
|
18 |
+
"""
|
19 |
+
logger.info(f"use excel_to_text with param: {path_or_url}")
|
20 |
+
try:
|
21 |
+
excel = load_file(path_or_url)
|
22 |
+
df = pd.read_excel(excel)
|
23 |
+
return df.to_markdown(index=False)
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
return f"Error reading Excel file: {str(e)}"
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
print(excel_to_text.invoke("../7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"))
|
31 |
+
print(
|
32 |
+
excel_to_text.invoke("https://agents-course-unit4-scoring.hf.space/files/7bd855d8-463d-4ed5-93ca-5fe35145f733"))
|