Spaces:
Build error
Build error
Add Excel tool
Browse files- agent.py +2 -1
- tools/file_tools.py +29 -0
agent.py
CHANGED
|
@@ -13,6 +13,7 @@ from supabase.client import Client, create_client
|
|
| 13 |
from tools.math_tools import add, subtract, multiply, divide, modulus, power, sqrt
|
| 14 |
from tools.search_tools import search_wikipedia, web_search
|
| 15 |
from tools.image_video_tools import query_image
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
# embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") # dim=768
|
|
@@ -40,7 +41,7 @@ def build_graph():
|
|
| 40 |
max_retries=2,
|
| 41 |
google_api_key=os.getenv("GOOGLE_API_KEY") # Get API key from environment variable
|
| 42 |
)
|
| 43 |
-
tools = [add, subtract, multiply, divide, modulus, power, sqrt, web_search, search_wikipedia, query_image]
|
| 44 |
|
| 45 |
llm_with_tools = llm.bind_tools(tools)
|
| 46 |
|
|
|
|
| 13 |
from tools.math_tools import add, subtract, multiply, divide, modulus, power, sqrt
|
| 14 |
from tools.search_tools import search_wikipedia, web_search
|
| 15 |
from tools.image_video_tools import query_image
|
| 16 |
+
from tools.file_tools import analyze_excel_file
|
| 17 |
|
| 18 |
|
| 19 |
# embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") # dim=768
|
|
|
|
| 41 |
max_retries=2,
|
| 42 |
google_api_key=os.getenv("GOOGLE_API_KEY") # Get API key from environment variable
|
| 43 |
)
|
| 44 |
+
tools = [add, subtract, multiply, divide, modulus, power, sqrt, web_search, search_wikipedia, query_image, analyze_excel_file]
|
| 45 |
|
| 46 |
llm_with_tools = llm.bind_tools(tools)
|
| 47 |
|
tools/file_tools.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from langchain_core.tools import tool
|
| 3 |
+
|
| 4 |
+
@tool
|
| 5 |
+
def analyze_excel_file(file_path: str, query: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Analyzes an Excel file using pandas and answer a question about it.
|
| 8 |
+
Args:
|
| 9 |
+
file_path (str): the path to the Excel file.
|
| 10 |
+
query (str): Question about the data
|
| 11 |
+
"""
|
| 12 |
+
try:
|
| 13 |
+
# Read the Excel file
|
| 14 |
+
df = pd.read_excel(file_path)
|
| 15 |
+
|
| 16 |
+
# Run various analyses based on the query
|
| 17 |
+
result = (
|
| 18 |
+
f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
| 19 |
+
)
|
| 20 |
+
result += f"Columns: {', '.join(df.columns)}\n\n"
|
| 21 |
+
|
| 22 |
+
# Add summary statistics
|
| 23 |
+
result += "Summary statistics:\n"
|
| 24 |
+
result += str(df.describe())
|
| 25 |
+
|
| 26 |
+
return result
|
| 27 |
+
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return f"Error analyzing Excel file: {str(e)}"
|