Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,28 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 2 |
import datetime
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
|
|
|
|
|
|
| 5 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 6 |
from Gradio_UI import GradioUI
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
| 9 |
@tool
|
| 10 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 11 |
-
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
|
|
|
| 13 |
tz = pytz.timezone(timezone)
|
|
|
|
| 14 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 15 |
return f"The current local time in {timezone} is: {local_time}"
|
| 16 |
except Exception as e:
|
|
@@ -18,25 +30,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 18 |
|
| 19 |
|
| 20 |
final_answer = FinalAnswerTool()
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
model = HfApiModel(
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
| 29 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 30 |
|
| 31 |
with open("prompts.yaml", 'r') as stream:
|
| 32 |
prompt_templates = yaml.safe_load(stream)
|
| 33 |
-
|
| 34 |
agent = CodeAgent(
|
| 35 |
model=model,
|
| 36 |
-
tools=[
|
| 37 |
max_steps=6,
|
| 38 |
verbosity_level=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
prompt_templates=prompt_templates
|
| 40 |
)
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
+
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
from typing import List, Dict
|
| 7 |
+
from tools.web_search import DuckDuckGoSearchTool
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
+
|
| 10 |
+
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
| 13 |
|
| 14 |
+
web_search = DuckDuckGoSearchTool() # <— fertiges Tool aus smolagents
|
| 15 |
+
|
| 16 |
@tool
|
| 17 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 18 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 19 |
+
Args:
|
| 20 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 21 |
+
"""
|
| 22 |
try:
|
| 23 |
+
# Create timezone object
|
| 24 |
tz = pytz.timezone(timezone)
|
| 25 |
+
# Get current time in that timezone
|
| 26 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 27 |
return f"The current local time in {timezone} is: {local_time}"
|
| 28 |
except Exception as e:
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
final_answer = FinalAnswerTool()
|
| 33 |
+
|
| 34 |
+
# 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:
|
| 35 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 36 |
|
| 37 |
model = HfApiModel(
|
| 38 |
+
max_tokens=2096,
|
| 39 |
+
temperature=0.5,
|
| 40 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 41 |
+
custom_role_conversions=None,
|
| 42 |
)
|
| 43 |
|
| 44 |
+
|
| 45 |
+
# Import tool from Hub
|
| 46 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 47 |
|
| 48 |
with open("prompts.yaml", 'r') as stream:
|
| 49 |
prompt_templates = yaml.safe_load(stream)
|
| 50 |
+
|
| 51 |
agent = CodeAgent(
|
| 52 |
model=model,
|
| 53 |
+
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 54 |
max_steps=6,
|
| 55 |
verbosity_level=1,
|
| 56 |
+
grammar=None,
|
| 57 |
+
planning_interval=None,
|
| 58 |
+
name=None,
|
| 59 |
+
description=None,
|
| 60 |
prompt_templates=prompt_templates
|
| 61 |
)
|
| 62 |
|
| 63 |
+
|
| 64 |
+
GradioUI(agent).launch()
|