Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,22 +27,34 @@ class WebSearchTool(Tool):
|
|
| 27 |
|
| 28 |
class LoadCsvTool(Tool):
|
| 29 |
name = "load_csv"
|
| 30 |
-
description = "
|
| 31 |
inputs = {
|
| 32 |
"file_path": {
|
| 33 |
"type": "string",
|
| 34 |
-
"description": "
|
| 35 |
}
|
| 36 |
}
|
| 37 |
output_type = "string"
|
| 38 |
|
| 39 |
def forward(self, file_path: str) -> str:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
#
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
)
|