giulia-fontanella commited on
Commit
376c5f5
·
verified ·
1 Parent(s): 640deab

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +42 -1
tools.py CHANGED
@@ -7,7 +7,48 @@ from langchain_community.document_loaders import ArxivLoader
7
 
8
 
9
  @tool
10
- def extract_text(img_path: str) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  """
12
  Extract text from an image file using a multimodal model.
13
 
 
7
 
8
 
9
  @tool
10
+ def read_excel(file_path: str) -> str:
11
+ """
12
+ Extract readable text from an Excel file (.xlsx or .xls).
13
+
14
+ Args:
15
+ file_path: Path to the Excel file.
16
+
17
+ Returns:
18
+ A string representation of all sheets and their content.
19
+ """
20
+ try:
21
+ df_dict = pd.read_excel(file_path, sheet_name=None) # Read all sheets
22
+ result = []
23
+ for sheet_name, sheet_df in df_dict.items():
24
+ sheet_text = sheet_df.to_string(index=False)
25
+ result.append(f"Sheet: {sheet_name}\n{sheet_text}")
26
+ return "\n\n".join(result)
27
+
28
+ except Exception as e:
29
+ return f"Error reading Excel file: {str(e)}"
30
+
31
+
32
+ @tool
33
+ def read_python(file_path: str) -> str:
34
+ """
35
+ Extract source code from a Python (.py) file.
36
+
37
+ Args:
38
+ file_path: Path to the Python file.
39
+
40
+ Returns:
41
+ A string containing the full source code of the file.
42
+ """
43
+ try:
44
+ with open(file_path, "r", encoding="utf-8") as f:
45
+ return f.read()
46
+ except Exception as e:
47
+ return f"Error reading Python file: {str(e)}"
48
+
49
+
50
+ @tool
51
+ def extract_text_from_image(img_path: str) -> str:
52
  """
53
  Extract text from an image file using a multimodal model.
54