Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,27 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
#
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -35,14 +46,10 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 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:
|
| 40 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
-
|
| 42 |
model = HfApiModel(
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
@@ -55,7 +62,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Custom tool to fetch webpage title
|
| 11 |
@tool
|
| 12 |
+
def fetch_webpage_title(url: str) -> str:
|
| 13 |
+
"""A tool that fetches the title of a webpage.
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
url: The URL of the webpage to fetch.
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
The title of the webpage.
|
| 20 |
"""
|
| 21 |
+
try:
|
| 22 |
+
response = requests.get(url)
|
| 23 |
+
response.raise_for_status() # Raise an exception for invalid responses
|
| 24 |
+
# Extract title from the HTML
|
| 25 |
+
from bs4 import BeautifulSoup
|
| 26 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 27 |
+
title = soup.title.string if soup.title else "No title found"
|
| 28 |
+
return f"The title of the webpage at {url} is: {title}"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error fetching webpage title: {str(e)}"
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
model = HfApiModel(
|
| 50 |
max_tokens=2096,
|
| 51 |
temperature=0.5,
|
| 52 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 53 |
custom_role_conversions=None,
|
| 54 |
)
|
| 55 |
|
|
|
|
| 62 |
|
| 63 |
agent = CodeAgent(
|
| 64 |
model=model,
|
| 65 |
+
tools=[final_answer, DuckDuckGoSearchTool(), image_generation_tool, fetch_webpage_title],
|
| 66 |
max_steps=6,
|
| 67 |
verbosity_level=1,
|
| 68 |
grammar=None,
|