Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded a new tool called promote Chakwal
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -52,6 +52,45 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
52 |
|
53 |
return "\n".join(messages)
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
@tool
|
57 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -90,7 +129,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
90 |
|
91 |
agent = CodeAgent(
|
92 |
model=model,
|
93 |
-
tools=[final_answer,my_custom_tool,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
94 |
max_steps=6,
|
95 |
verbosity_level=1,
|
96 |
grammar=None,
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, image_generation_tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
|
|
52 |
|
53 |
return "\n".join(messages)
|
54 |
|
55 |
+
@tool
|
56 |
+
def promote_chakwal(arg1: str, arg2: int) -> str:
|
57 |
+
"""
|
58 |
+
A tool that promotes tourism and investment in Chakwal by fetching live information
|
59 |
+
and generating a visual representation of the city's attractions.
|
60 |
+
|
61 |
+
Args:
|
62 |
+
arg1: A custom note or call-to-action message.
|
63 |
+
arg2: The number of search results to include from DuckDuckGo regarding tourism/investment.
|
64 |
+
"""
|
65 |
+
output_lines = []
|
66 |
+
|
67 |
+
# Use DuckDuckGoSearchTool to fetch current news or information on Chakwal tourism and investment
|
68 |
+
duck_tool = DuckDuckGoSearchTool()
|
69 |
+
search_query = "Chakwal tourism investment latest news attractions"
|
70 |
+
search_results = duck_tool.run(search_query)
|
71 |
+
|
72 |
+
# Process and include search results (assuming a list of result dictionaries)
|
73 |
+
if isinstance(search_results, list):
|
74 |
+
output_lines.append("Latest Information on Chakwal:")
|
75 |
+
for idx, result in enumerate(search_results[:arg2]):
|
76 |
+
title = result.get("title", "No Title")
|
77 |
+
snippet = result.get("snippet", "No snippet available.")
|
78 |
+
output_lines.append(f"{idx+1}. {title} - {snippet}")
|
79 |
+
else:
|
80 |
+
output_lines.append(f"Search Results: {search_results}")
|
81 |
+
|
82 |
+
# Use the text-to-image generation tool to create an attractive image prompt for Chakwal
|
83 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
84 |
+
image_prompt = "A stunning view of Chakwal with lush landscapes, historic landmarks, and vibrant local culture"
|
85 |
+
generated_image = image_generation_tool.run(image_prompt)
|
86 |
+
output_lines.append("\nVisual Promotion:")
|
87 |
+
output_lines.append(f"Generated Image URL/Result: {generated_image}")
|
88 |
+
|
89 |
+
# Append any additional note from arg1
|
90 |
+
if arg1:
|
91 |
+
output_lines.append(f"\nAdditional Note: {arg1}")
|
92 |
+
|
93 |
+
return "\n".join(output_lines)
|
94 |
|
95 |
@tool
|
96 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
129 |
|
130 |
agent = CodeAgent(
|
131 |
model=model,
|
132 |
+
tools=[final_answer,my_custom_tool,get_current_time_in_timezone,promote_chakwal], ## add your tools here (don't remove final answer)
|
133 |
max_steps=6,
|
134 |
verbosity_level=1,
|
135 |
grammar=None,
|