Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app req tools
Browse files- app.py +15 -7
- tools/final_answer.py +6 -1
app.py
CHANGED
@@ -7,7 +7,7 @@ import yaml
|
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
|
11 |
def extract_text_tool(url: str) -> str:
|
12 |
"""A tool that extracts clean text content from a webpage
|
13 |
Args:
|
@@ -20,7 +20,10 @@ def extract_text_tool(url: str) -> str:
|
|
20 |
except Exception as e:
|
21 |
return f"Error extracting text: {str(e)}"
|
22 |
|
23 |
-
|
|
|
|
|
|
|
24 |
def get_current_time_in_timezone(timezone: str) -> str:
|
25 |
"""A tool that fetches the current local time in a specified timezone.
|
26 |
Args:
|
@@ -33,9 +36,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
-
|
|
|
|
|
|
|
37 |
final_answer = FinalAnswerTool()
|
38 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
|
39 |
|
40 |
# Setup the model
|
41 |
model = HfApiModel(
|
@@ -57,10 +65,10 @@ agent = CodeAgent(
|
|
57 |
model=model,
|
58 |
tools=[
|
59 |
final_answer,
|
60 |
-
search_tool,
|
61 |
-
tool(extract_text_tool),
|
62 |
-
tool(get_current_time_in_timezone),
|
63 |
-
image_generation_tool
|
64 |
],
|
65 |
max_steps=6,
|
66 |
verbosity_level=1,
|
|
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
@tool
|
11 |
def extract_text_tool(url: str) -> str:
|
12 |
"""A tool that extracts clean text content from a webpage
|
13 |
Args:
|
|
|
20 |
except Exception as e:
|
21 |
return f"Error extracting text: {str(e)}"
|
22 |
|
23 |
+
extract_text_tool.name = "extract_text"
|
24 |
+
extract_text_tool.description = "Extracts text content from a URL"
|
25 |
+
|
26 |
+
@tool
|
27 |
def get_current_time_in_timezone(timezone: str) -> str:
|
28 |
"""A tool that fetches the current local time in a specified timezone.
|
29 |
Args:
|
|
|
36 |
except Exception as e:
|
37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
38 |
|
39 |
+
get_current_time_in_timezone.name = "get_time"
|
40 |
+
get_current_time_in_timezone.description = "Gets current time in a specific timezone"
|
41 |
+
|
42 |
+
# Initialize tools
|
43 |
final_answer = FinalAnswerTool()
|
44 |
search_tool = DuckDuckGoSearchTool()
|
45 |
+
search_tool.name = "web_search"
|
46 |
+
search_tool.description = "Searches the web for information"
|
47 |
|
48 |
# Setup the model
|
49 |
model = HfApiModel(
|
|
|
65 |
model=model,
|
66 |
tools=[
|
67 |
final_answer,
|
68 |
+
search_tool,
|
69 |
+
tool(extract_text_tool),
|
70 |
+
tool(get_current_time_in_timezone),
|
71 |
+
image_generation_tool
|
72 |
],
|
73 |
max_steps=6,
|
74 |
verbosity_level=1,
|
tools/final_answer.py
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
# tools/final_answer.py
|
2 |
from typing import Any
|
|
|
3 |
|
|
|
4 |
class FinalAnswerTool:
|
|
|
|
|
|
|
5 |
def __call__(self, answer: str) -> str:
|
6 |
"""Tool to provide a final answer
|
7 |
Args:
|
@@ -10,4 +15,4 @@ class FinalAnswerTool:
|
|
10 |
return answer
|
11 |
|
12 |
def __str__(self) -> str:
|
13 |
-
return
|
|
|
1 |
# tools/final_answer.py
|
2 |
from typing import Any
|
3 |
+
from smolagents import tool
|
4 |
|
5 |
+
@tool
|
6 |
class FinalAnswerTool:
|
7 |
+
name = "final_answer" # Required by smolagents
|
8 |
+
description = "A tool to provide the final answer"
|
9 |
+
|
10 |
def __call__(self, answer: str) -> str:
|
11 |
"""Tool to provide a final answer
|
12 |
Args:
|
|
|
15 |
return answer
|
16 |
|
17 |
def __str__(self) -> str:
|
18 |
+
return self.name
|