rhagenba commited on
Commit
7c2fd9b
·
verified ·
1 Parent(s): 8afc21e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -47
app.py CHANGED
@@ -1,44 +1,16 @@
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
- @tool
15
- def web_search(query: str, max_results: int = 5) -> List[Dict[str, str]]:
16
- """
17
- Führt eine Websuche mit DuckDuckGo durch und gibt strukturierte Ergebnisse zurück.
18
- """
19
- results = []
20
- with DDGS() as ddgs:
21
- for result in ddgs.text(query, max_results=max_results):
22
- results.append({
23
- "title": result.get("title"),
24
- "url": result.get("href"),
25
- "snippet": result.get("body")
26
- })
27
- return results
28
-
29
-
30
- web_search = DuckDuckGoSearchTool
31
-
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
34
- """A tool that fetches the current local time in a specified timezone.
35
- Args:
36
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
37
- """
38
  try:
39
- # Create timezone object
40
  tz = pytz.timezone(timezone)
41
- # Get current time in that timezone
42
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
43
  return f"The current local time in {timezone} is: {local_time}"
44
  except Exception as e:
@@ -46,35 +18,25 @@ def get_current_time_in_timezone(timezone: str) -> str:
46
 
47
 
48
  final_answer = FinalAnswerTool()
49
-
50
- # 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:
51
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
52
 
53
  model = HfApiModel(
54
- max_tokens=2096,
55
- temperature=0.5,
56
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
57
- custom_role_conversions=None,
58
  )
59
 
60
-
61
- # Import tool from Hub
62
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
63
 
64
  with open("prompts.yaml", 'r') as stream:
65
  prompt_templates = yaml.safe_load(stream)
66
-
67
  agent = CodeAgent(
68
  model=model,
69
- tools=[final_answer], ## add your tools here (don't remove final answer)
70
  max_steps=6,
71
  verbosity_level=1,
72
- grammar=None,
73
- planning_interval=None,
74
- name=None,
75
- description=None,
76
  prompt_templates=prompt_templates
77
  )
78
 
79
-
80
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
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
 
19
 
20
  final_answer = FinalAnswerTool()
21
+ web_search = DuckDuckGoSearchTool() # <— fertiges Tool aus smolagents
 
 
22
 
23
  model = HfApiModel(
24
+ max_tokens=2096,
25
+ temperature=0.5,
26
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
 
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=[web_search, get_current_time_in_timezone, final_answer],
37
  max_steps=6,
38
  verbosity_level=1,
 
 
 
 
39
  prompt_templates=prompt_templates
40
  )
41
 
42
+ GradioUI(agent).launch()