Spaces:
Runtime error
Runtime error
Added tools to the app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,20 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -34,6 +40,10 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -55,7 +65,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def web_scrapping_tool(url:str)-> str:
|
| 13 |
+
|
| 14 |
+
"""Fetches and returns the text content of a webpage.
|
| 15 |
Args:
|
| 16 |
+
url: the web page url
|
|
|
|
| 17 |
"""
|
| 18 |
+
from bs4 import BeautifulSoup
|
| 19 |
+
try:
|
| 20 |
+
response = requests.get(url, timeout = 10)
|
| 21 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 22 |
+
return soup.get_text()[:3000]
|
| 23 |
+
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f'Error :{str(e)}'
|
| 26 |
|
| 27 |
@tool
|
| 28 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 40 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 41 |
|
| 42 |
|
| 43 |
+
# Adding the search tool
|
| 44 |
+
search_tool = DuckDuckGoSearchTool()
|
| 45 |
+
|
| 46 |
+
# Finale answer tool
|
| 47 |
final_answer = FinalAnswerTool()
|
| 48 |
|
| 49 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 65 |
|
| 66 |
agent = CodeAgent(
|
| 67 |
model=model,
|
| 68 |
+
tools=[final_answer, web_scrapping_tool, ], ## add your tools here (don't remove final answer)
|
| 69 |
max_steps=6,
|
| 70 |
verbosity_level=1,
|
| 71 |
grammar=None,
|