Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,31 +9,60 @@ 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 my_custom_tool(
|
| 13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
| 24 |
Args:
|
| 25 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
-
# Create timezone object
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
-
# Get current time in that timezone
|
| 31 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 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:
|
|
@@ -46,7 +75,6 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
|
@@ -55,13 +83,13 @@ 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,
|
| 62 |
planning_interval=None,
|
| 63 |
-
name=
|
| 64 |
-
description=
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(topic: str, num_results: int) -> str: # it's important to specify the return type
|
| 13 |
+
# Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that analyzes latest technology trends using web search.
|
| 15 |
Args:
|
| 16 |
+
topic: The technology topic to analyze (e.g., artificial intelligence, robotics, blockchain).
|
| 17 |
+
num_results: Number of trend highlights the user wants.
|
| 18 |
"""
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
search = DuckDuckGoSearchTool()
|
| 22 |
+
results = search.run(f"latest trends and news in {topic}")
|
| 23 |
+
|
| 24 |
+
report = f"""
|
| 25 |
+
Tech Trend Analysis
|
| 26 |
+
|
| 27 |
+
Topic: {topic}
|
| 28 |
+
Requested highlights: {num_results}
|
| 29 |
+
|
| 30 |
+
Latest insights:
|
| 31 |
+
{results}
|
| 32 |
+
|
| 33 |
+
Summary:
|
| 34 |
+
These are some of the latest discussions, innovations, and industry
|
| 35 |
+
movements related to the topic. This helps users quickly understand
|
| 36 |
+
what is trending in technology right now.
|
| 37 |
+
"""
|
| 38 |
+
return report
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"Error analyzing tech trends: {str(e)}"
|
| 42 |
+
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 46 |
"""A tool that fetches the current local time in a specified timezone.
|
| 47 |
Args:
|
| 48 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York', 'Asia/Kolkata').
|
| 49 |
"""
|
| 50 |
try:
|
|
|
|
| 51 |
tz = pytz.timezone(timezone)
|
|
|
|
| 52 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 53 |
+
|
| 54 |
+
return f"""
|
| 55 |
+
Timezone Information
|
| 56 |
+
|
| 57 |
+
Timezone: {timezone}
|
| 58 |
+
Current Local Time: {local_time}
|
| 59 |
+
|
| 60 |
+
This helps users know the exact local time in different parts of the world.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
except Exception as e:
|
| 64 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 65 |
|
|
|
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|
| 68 |
# 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:
|
|
|
|
| 75 |
custom_role_conversions=None,
|
| 76 |
)
|
| 77 |
|
|
|
|
| 78 |
# Import tool from Hub
|
| 79 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 80 |
|
|
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
+
tools=[final_answer, my_custom_tool, get_current_time_in_timezone, image_generation_tool],
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|
| 90 |
planning_interval=None,
|
| 91 |
+
name="Tech Trends AI Agent",
|
| 92 |
+
description="An AI assistant that analyzes technology trends, provides worldwide time information, and generates images.",
|
| 93 |
prompt_templates=prompt_templates
|
| 94 |
)
|
| 95 |
|