Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import pandas as pd
|
|
| 13 |
# from langchain.llms.base import LLM
|
| 14 |
# from huggingface_hub import InferenceClient
|
| 15 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 16 |
-
|
| 17 |
|
| 18 |
# (Keep Constants as is)
|
| 19 |
# --- Constants ---
|
|
@@ -30,6 +30,17 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 30 |
|
| 31 |
# --- Basic Agent Definition ---
|
| 32 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
class BasicAgent:
|
| 34 |
def __init__(self):
|
| 35 |
print("BasicAgent initialized.")
|
|
@@ -40,17 +51,24 @@ class BasicAgent:
|
|
| 40 |
"Always return a direct answer, no extra text or explanation. "
|
| 41 |
"If a question asks for a count, return only the number."
|
| 42 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
model = InferenceClientModel(
|
| 45 |
model_id="gpt-4o",
|
| 46 |
token=openaikey,
|
| 47 |
-
provider="openai"
|
| 48 |
-
temperature=0.0 # 0.7 by default (not sure)
|
| 49 |
)
|
| 50 |
|
| 51 |
|
| 52 |
self.agent = ToolCallingAgent(
|
| 53 |
-
tools=[DuckDuckGoSearchTool()],
|
| 54 |
model=model
|
| 55 |
)
|
| 56 |
|
|
|
|
| 13 |
# from langchain.llms.base import LLM
|
| 14 |
# from huggingface_hub import InferenceClient
|
| 15 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 16 |
+
from smolagent.tools import Tool
|
| 17 |
|
| 18 |
# (Keep Constants as is)
|
| 19 |
# --- Constants ---
|
|
|
|
| 30 |
|
| 31 |
# --- Basic Agent Definition ---
|
| 32 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 33 |
+
# --- Excel Reading Tool ---
|
| 34 |
+
def read_excel_tool(file_path: str) -> str:
|
| 35 |
+
try:
|
| 36 |
+
if file_path.endswith('.csv'):
|
| 37 |
+
df = pd.read_csv(file_path)
|
| 38 |
+
else:
|
| 39 |
+
df = pd.read_excel(file_path)
|
| 40 |
+
return df.head(10).to_string(index=False)
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error reading file: {str(e)}"
|
| 43 |
+
|
| 44 |
class BasicAgent:
|
| 45 |
def __init__(self):
|
| 46 |
print("BasicAgent initialized.")
|
|
|
|
| 51 |
"Always return a direct answer, no extra text or explanation. "
|
| 52 |
"If a question asks for a count, return only the number."
|
| 53 |
)
|
| 54 |
+
|
| 55 |
+
# Register Excel tool
|
| 56 |
+
read_excel = Tool.from_function(
|
| 57 |
+
func=read_excel_tool,
|
| 58 |
+
name="read_excel",
|
| 59 |
+
description="Reads Excel or CSV file and returns the first 10 rows as a string."
|
| 60 |
+
)
|
| 61 |
|
| 62 |
model = InferenceClientModel(
|
| 63 |
model_id="gpt-4o",
|
| 64 |
token=openaikey,
|
| 65 |
+
provider="openai"#,
|
| 66 |
+
# temperature=0.0 # 0.7 by default (not sure)
|
| 67 |
)
|
| 68 |
|
| 69 |
|
| 70 |
self.agent = ToolCallingAgent(
|
| 71 |
+
tools=[DuckDuckGoSearchTool(), read_excel],
|
| 72 |
model=model
|
| 73 |
)
|
| 74 |
|