Spaces:
Sleeping
Sleeping
improed flow
Browse files
tools.py
CHANGED
|
@@ -602,9 +602,9 @@ python_repl_tool = Tool(
|
|
| 602 |
# --- New Tools ---
|
| 603 |
|
| 604 |
|
| 605 |
-
def extract_text_from_image(
|
| 606 |
try:
|
| 607 |
-
image = Image.open(
|
| 608 |
text = pytesseract.image_to_string(image)
|
| 609 |
return f"Extracted text from image:\n\n{text}"
|
| 610 |
except Exception as e:
|
|
@@ -618,7 +618,8 @@ extract_text_from_image_tool = Tool(
|
|
| 618 |
)
|
| 619 |
|
| 620 |
|
| 621 |
-
def
|
|
|
|
| 622 |
try:
|
| 623 |
df = pd.read_csv(file_path)
|
| 624 |
result = f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
|
@@ -632,12 +633,13 @@ def analyze_csv_file(file_path: str, query: str) -> str:
|
|
| 632 |
|
| 633 |
analyze_csv_file_tool = Tool(
|
| 634 |
name="analyze_csv_file_tool",
|
| 635 |
-
func=
|
| 636 |
description="Analyze a CSV file using pandas and answer a question about it."
|
| 637 |
)
|
| 638 |
|
| 639 |
|
| 640 |
-
def
|
|
|
|
| 641 |
try:
|
| 642 |
df = pd.read_excel(file_path)
|
| 643 |
result = f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
|
@@ -649,24 +651,10 @@ def analyze_excel_file(file_path: str, query: str) -> str:
|
|
| 649 |
return f"Error analyzing Excel file: {str(e)}"
|
| 650 |
|
| 651 |
|
| 652 |
-
def analyze_excel_file_simple(file_path: str) -> str:
|
| 653 |
-
"""Wrapper for analyze_excel_file that uses a default query."""
|
| 654 |
-
return analyze_excel_file(file_path, "Analyze this spreadsheet")
|
| 655 |
-
|
| 656 |
-
|
| 657 |
analyze_excel_file_tool = Tool(
|
| 658 |
name="analyze_excel_file_tool",
|
| 659 |
func=analyze_excel_file_simple,
|
| 660 |
description="Analyze an Excel file using pandas and answer a question about it."
|
| 661 |
)
|
| 662 |
|
| 663 |
-
#
|
| 664 |
-
# Smart File Download Tool (Consolidated)
|
| 665 |
-
# =========================
|
| 666 |
-
|
| 667 |
-
# Note: This tool is no longer needed since files are pre-processed
|
| 668 |
-
# when questions are fetched. The agent receives file content directly.
|
| 669 |
-
|
| 670 |
-
# =========================
|
| 671 |
-
# Image and Data Analysis Tools
|
| 672 |
-
# =========================
|
|
|
|
| 602 |
# --- New Tools ---
|
| 603 |
|
| 604 |
|
| 605 |
+
def extract_text_from_image(file_path: str) -> str:
|
| 606 |
try:
|
| 607 |
+
image = Image.open(file_path)
|
| 608 |
text = pytesseract.image_to_string(image)
|
| 609 |
return f"Extracted text from image:\n\n{text}"
|
| 610 |
except Exception as e:
|
|
|
|
| 618 |
)
|
| 619 |
|
| 620 |
|
| 621 |
+
def analyze_csv_file_simple(file_path: str) -> str:
|
| 622 |
+
"""Analyze a CSV file using pandas."""
|
| 623 |
try:
|
| 624 |
df = pd.read_csv(file_path)
|
| 625 |
result = f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
|
|
|
| 633 |
|
| 634 |
analyze_csv_file_tool = Tool(
|
| 635 |
name="analyze_csv_file_tool",
|
| 636 |
+
func=analyze_csv_file_simple,
|
| 637 |
description="Analyze a CSV file using pandas and answer a question about it."
|
| 638 |
)
|
| 639 |
|
| 640 |
|
| 641 |
+
def analyze_excel_file_simple(file_path: str) -> str:
|
| 642 |
+
"""Analyze an Excel file using pandas."""
|
| 643 |
try:
|
| 644 |
df = pd.read_excel(file_path)
|
| 645 |
result = f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
|
|
|
| 651 |
return f"Error analyzing Excel file: {str(e)}"
|
| 652 |
|
| 653 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
analyze_excel_file_tool = Tool(
|
| 655 |
name="analyze_excel_file_tool",
|
| 656 |
func=analyze_excel_file_simple,
|
| 657 |
description="Analyze an Excel file using pandas and answer a question about it."
|
| 658 |
)
|
| 659 |
|
| 660 |
+
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|