Update tools.py
Browse files
tools.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from smolagents import DuckDuckGoSearchTool
|
| 2 |
import random
|
| 3 |
from huggingface_hub import list_models
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def get_hub_stats(author: str) -> str:
|
| 6 |
"""Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
|
|
@@ -114,4 +116,47 @@ def analyze_image(image_path: str, question: str = "What do you see in this imag
|
|
| 114 |
return response.content
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
-
return f"Error analyzing image: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import DuckDuckGoSearchTool
|
| 2 |
import random
|
| 3 |
from huggingface_hub import list_models
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
def get_hub_stats(author: str) -> str:
|
| 8 |
"""Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
|
|
|
|
| 116 |
return response.content
|
| 117 |
|
| 118 |
except Exception as e:
|
| 119 |
+
return f"Error analyzing image: {e}"
|
| 120 |
+
|
| 121 |
+
def read_excel_file(file_path: str) -> Dict[str, Any]:
|
| 122 |
+
"""
|
| 123 |
+
Reads an Excel file and returns structured information about its contents
|
| 124 |
+
|
| 125 |
+
Args:
|
| 126 |
+
file_path: Path to the Excel file
|
| 127 |
+
|
| 128 |
+
Returns:
|
| 129 |
+
Dictionary containing file analysis
|
| 130 |
+
"""
|
| 131 |
+
try:
|
| 132 |
+
# Read all sheets
|
| 133 |
+
excel_file = pd.ExcelFile(file_path)
|
| 134 |
+
sheet_names = excel_file.sheet_names
|
| 135 |
+
|
| 136 |
+
result = {
|
| 137 |
+
"file_path": file_path,
|
| 138 |
+
"sheet_names": sheet_names,
|
| 139 |
+
"sheets_data": {},
|
| 140 |
+
"summary": {}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
for sheet_name in sheet_names:
|
| 144 |
+
df = pd.read_excel(file_path, sheet_name=sheet_name)
|
| 145 |
+
|
| 146 |
+
# Basic info about the sheet
|
| 147 |
+
sheet_info = {
|
| 148 |
+
"shape": df.shape,
|
| 149 |
+
"columns": df.columns.tolist(),
|
| 150 |
+
"dtypes": df.dtypes.to_dict(),
|
| 151 |
+
"data": df,
|
| 152 |
+
"sample_data": df.head().to_dict(),
|
| 153 |
+
"numeric_columns": df.select_dtypes(include=[np.number]).columns.tolist(),
|
| 154 |
+
"text_columns": df.select_dtypes(include=['object']).columns.tolist()
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
result["sheets_data"][sheet_name] = sheet_info
|
| 158 |
+
|
| 159 |
+
return result
|
| 160 |
+
|
| 161 |
+
except Exception as e:
|
| 162 |
+
return {"error": f"Failed to read Excel file: {str(e)}"}
|