Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,54 +8,59 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
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(arg1:str, arg2:int)-> str: #it's import 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 does nothing yet
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
-
"""
|
| 19 |
-
return "What magic will you build ?"
|
| 20 |
-
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
-
"""
|
| 24 |
Args:
|
| 25 |
-
timezone: A
|
| 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 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
# Import tool from Hub
|
| 51 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
-
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 8 |
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 get_current_time_in_timezone(timezone: str) -> str:
|
| 13 |
+
"""Fetches the current local time in a specified timezone.
|
| 14 |
Args:
|
| 15 |
+
timezone: A valid timezone string, e.g. 'Asia/Kolkata' or 'America/New_York'.
|
| 16 |
"""
|
| 17 |
try:
|
|
|
|
| 18 |
tz = pytz.timezone(timezone)
|
|
|
|
| 19 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 20 |
return f"The current local time in {timezone} is: {local_time}"
|
| 21 |
except Exception as e:
|
| 22 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 23 |
|
| 24 |
+
@tool
|
| 25 |
+
def get_fun_fact(topic: str) -> str:
|
| 26 |
+
"""Returns a fun fact about a given topic using a public API.
|
| 27 |
+
Args:
|
| 28 |
+
topic: The subject to get a fun fact about, e.g. 'math', 'science'.
|
| 29 |
+
"""
|
| 30 |
+
try:
|
| 31 |
+
response = requests.get(
|
| 32 |
+
f"https://uselessfacts.jsph.pl/api/v2/facts/random?language=en",
|
| 33 |
+
timeout=5
|
| 34 |
+
)
|
| 35 |
+
data = response.json()
|
| 36 |
+
return f"Fun fact about {topic}: {data.get('text', 'No fact found.')}"
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error fetching fun fact: {str(e)}"
|
| 39 |
|
|
|
|
| 40 |
|
| 41 |
+
ffinal_answer = FinalAnswerTool()
|
| 42 |
+
search_tool = DuckDuckGoSearchTool()
|
| 43 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 44 |
|
| 45 |
+
# ── Model Setup ───────────────────────────────────────────────────────────────
|
| 46 |
+
model = InferenceClientModel(
|
| 47 |
+
max_tokens=2096,
|
| 48 |
+
temperature=0.5,
|
| 49 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 50 |
+
custom_role_conversions=None,
|
| 51 |
)
|
| 52 |
|
| 53 |
+
# ── Load System Prompt ────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
| 54 |
with open("prompts.yaml", 'r') as stream:
|
| 55 |
prompt_templates = yaml.safe_load(stream)
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
+
tools=[final_answer,
|
| 60 |
+
search_tool, # Web search via DuckDuckGo
|
| 61 |
+
image_generation_tool, # Text-to-image generation
|
| 62 |
+
get_current_time_in_timezone, # Timezone checker
|
| 63 |
+
get_fun_fact,], ## add your tools here (don't remove final answer)
|
| 64 |
max_steps=6,
|
| 65 |
verbosity_level=1,
|
| 66 |
grammar=None,
|