Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,20 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 33 |
# --- Excel Reading Tool ---
|
| 34 |
@tool
|
| 35 |
def read_excel_tool(file_path: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
if file_path.endswith('.csv'):
|
| 38 |
df = pd.read_csv(file_path)
|
|
@@ -41,7 +55,8 @@ def read_excel_tool(file_path: str) -> str:
|
|
| 41 |
return df.head(10).to_string(index=False)
|
| 42 |
except Exception as e:
|
| 43 |
return f"Error reading file: {str(e)}"
|
| 44 |
-
|
|
|
|
| 45 |
class BasicAgent:
|
| 46 |
def __init__(self):
|
| 47 |
print("BasicAgent initialized.")
|
|
|
|
| 33 |
# --- Excel Reading Tool ---
|
| 34 |
@tool
|
| 35 |
def read_excel_tool(file_path: str) -> str:
|
| 36 |
+
"""
|
| 37 |
+
Reads the contents of an Excel (.xlsx) or CSV (.csv) file and returns the first 10 rows as a formatted string.
|
| 38 |
+
|
| 39 |
+
Parameters:
|
| 40 |
+
file_path (str): The full path to the Excel or CSV file.
|
| 41 |
+
|
| 42 |
+
Returns:
|
| 43 |
+
str: A string representation of the first 10 rows of the file, or an error message if reading fails.
|
| 44 |
+
|
| 45 |
+
Notes:
|
| 46 |
+
- CSV files are read using pandas.read_csv().
|
| 47 |
+
- Excel files are read using pandas.read_excel().
|
| 48 |
+
- Index column is omitted from the output for readability.
|
| 49 |
+
"""
|
| 50 |
try:
|
| 51 |
if file_path.endswith('.csv'):
|
| 52 |
df = pd.read_csv(file_path)
|
|
|
|
| 55 |
return df.head(10).to_string(index=False)
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error reading file: {str(e)}"
|
| 58 |
+
|
| 59 |
+
# --- Agent defining Class ---
|
| 60 |
class BasicAgent:
|
| 61 |
def __init__(self):
|
| 62 |
print("BasicAgent initialized.")
|