Isaac454 commited on
Commit
a22fe74
·
verified ·
1 Parent(s): 99bc0e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -27,22 +27,34 @@ class WebSearchTool(Tool):
27
 
28
  class LoadCsvTool(Tool):
29
  name = "load_csv"
30
- description = "reads a CSV (Comma-Separated Values) file from a specified file path on the local system and loads its contents into a pandas DataFrame for further data analysis or processing."
31
  inputs = {
32
  "file_path": {
33
  "type": "string",
34
- "description": "The full path to the CSV file on the local file system. This can be an absolute or relative path."
35
  }
36
  }
37
  output_type = "string"
38
 
39
  def forward(self, file_path: str) -> str:
40
- with open(file_path, "r", encoding="utf-8") as f:
41
- return f.read()
42
- # The original path caused a SyntaxError due to backslashes being interpreted as escape sequences.
43
- # Also, the path was incorrectly wrapped in an extra set of double quotes.
44
- # Using a raw string (r"...") prevents this. Note: This path is a local Windows path
45
- # and will likely not be accessible in this Colab environment.
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  class WikipediaTool(Tool):
48
  name = "wikipedia_search"
@@ -102,7 +114,7 @@ model = LiteLLMModel(
102
 
103
  # --- Initialize Tool-Calling Agent ---
104
  agent = ToolCallingAgent(
105
- tools=[WebSearchTool(), WikipediaTool(), WeatherTool(), LoadCsvTool],
106
  model=model,
107
  max_steps=10,
108
  )
 
27
 
28
  class LoadCsvTool(Tool):
29
  name = "load_csv"
30
+ description = "Load and analyze CSV file. Returns summary statistics and first few rows. Input: file path."
31
  inputs = {
32
  "file_path": {
33
  "type": "string",
34
+ "description": "Path to CSV file (e.g., 'data.csv' or '/app/data.csv')"
35
  }
36
  }
37
  output_type = "string"
38
 
39
  def forward(self, file_path: str) -> str:
40
+ try:
41
+ # Read CSV into DataFrame
42
+ df = pd.read_csv(file_path)
43
+
44
+ # Create summary
45
+ summary = f"CSV loaded successfully!\n\n"
46
+ summary += f"Rows: {len(df)}, Columns: {len(df.columns)}\n\n"
47
+ summary += f"Column names: {', '.join(df.columns.tolist())}\n\n"
48
+ summary += f"First 5 rows:\n{df.head().to_string()}\n\n"
49
+ summary += f"Data types:\n{df.dtypes.to_string()}\n\n"
50
+ summary += f"Summary statistics:\n{df.describe().to_string()}"
51
+
52
+ return summary
53
+
54
+ except FileNotFoundError:
55
+ return f"Error: File '{file_path}' not found!"
56
+ except Exception as e:
57
+ return f"Error loading CSV: {str(e)}".
58
 
59
  class WikipediaTool(Tool):
60
  name = "wikipedia_search"
 
114
 
115
  # --- Initialize Tool-Calling Agent ---
116
  agent = ToolCallingAgent(
117
+ tools=[WebSearchTool(), WikipediaTool(), WeatherTool(), LoadCsvTool()],
118
  model=model,
119
  max_steps=10,
120
  )