CindyDelage commited on
Commit
7836f1d
·
verified ·
1 Parent(s): 70b1089

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +56 -0
tools.py CHANGED
@@ -16,6 +16,62 @@ import pandas as pd
16
  from PIL import Image
17
  import html5lib
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  class is_commutative(Tool):
20
  name = "commutative"
21
  description = "Performs a study on a table set to see if it is commutative."
 
16
  from PIL import Image
17
  import html5lib
18
 
19
+ class read_python_file(Tool):
20
+ name = "reader_python"
21
+ description = "Read a python file. Will return the entire code in the file"
22
+ inputs = {
23
+ "file_name": {
24
+ "type": "string",
25
+ "description": "The python file path"
26
+ },
27
+ }
28
+ output_type = "string"
29
+
30
+ def forward(self, file_name):
31
+ try:
32
+ with open(file_name, "r", encoding="utf-8") as fichier:
33
+ contenu = fichier.read()
34
+ print("Contenu du fichier :\n")
35
+ return contenu
36
+
37
+ except FileNotFoundError:
38
+ print(f"Erreur : le fichier '{fichier_cible}' n'existe pas.")
39
+ return
40
+ except Exception as e:
41
+ print(f"Une erreur est survenue : {e}")
42
+ return
43
+
44
+ class read_excel_file(Tool):
45
+ name = "reader_excel"
46
+ description = "Read a excel file. Will return the entire info in the file"
47
+ inputs = {
48
+ "file_name": {
49
+ "type": "string",
50
+ "description": "The excel file path"
51
+ },
52
+ }
53
+ output_type = "string"
54
+
55
+ def forward(self, file_name):
56
+
57
+ try:
58
+ # Lecture de toutes les feuilles
59
+ xls = pd.ExcelFile(file_name)
60
+ print("Sheets :", xls.sheet_names)
61
+
62
+ # Lecture d'une feuille spécifique (ici, la première)
63
+ df = pd.read_excel(xls, sheet_name=xls.sheet_names[0])
64
+ print("\nContent of the sheet :\n")
65
+ return df
66
+
67
+ except FileNotFoundError:
68
+ print(f"Erreur : le fichier '{fichier_excel}' n'existe pas.")
69
+ return
70
+ except Exception as e:
71
+ print(f"Une erreur est survenue : {e}")
72
+ return
73
+
74
+
75
  class is_commutative(Tool):
76
  name = "commutative"
77
  description = "Performs a study on a table set to see if it is commutative."