Rayen-Mohad commited on
Commit
113c5a3
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -6
app.py CHANGED
@@ -8,15 +8,101 @@ 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:
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
12
+ import datetime
13
+ import requests
14
+ import pytz
15
+ import yaml
16
+ from tools.final_answer import FinalAnswerTool
17
+
18
+ from Gradio_UI import GradioUI
19
+
20
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
21
+
22
+ @tool
23
+ def get_today_football_matches() -> str:
24
+ """Fetches and displays today's football matches.
25
+ Returns:
26
+ A formatted string listing today's football matches with teams, competition, and match time.
27
+ """
28
+ from datetime import datetime
29
+ import requests
30
+
31
+ today = datetime.today().strftime('%Y-%m-%d')
32
+ api_url = f"https://api.football-data.org/v4/matches?dateFrom={today}&dateTo={today}"
33
+ headers = {"X-Auth-Token": " GET https://api.football-data.org/v4/matches"} # Replace with your actual API key
34
+
35
+ try:
36
+ response = requests.get(api_url, headers=headers)
37
+ if response.status_code != 200:
38
+ return "Failed to fetch matches. Please check your API key or try again later."
39
+
40
+ matches = response.json().get("matches", [])
41
+ if not matches:
42
+ return "No football matches found for today."
43
+
44
+ result = "⚽ Today's Football Matches ⚽\n"
45
+ for match in matches:
46
+ home = match["homeTeam"]["name"]
47
+ away = match["awayTeam"]["name"]
48
+ competition = match["competition"]["name"]
49
+ time = match["utcDate"].split("T")[1][:5] # Extracts HH:MM format
50
+
51
+ result += f"{home} vs {away} - {competition} at {time} UTC\n"
52
+
53
+ return result
54
+ except Exception as e:
55
+ return f"An error occurred: {str(e)}"
56
+
57
  @tool
58
+ def get_current_time_in_timezone(timezone: str) -> str:
59
+ """A tool that fetches the current local time in a specified timezone.
 
60
  Args:
61
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
62
  """
63
+ try:
64
+ # Create timezone object
65
+ tz = pytz.timezone(timezone)
66
+ # Get current time in that timezone
67
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
68
+ return f"The current local time in {timezone} is: {local_time}"
69
+ except Exception as e:
70
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
71
+
72
+
73
+ final_answer = FinalAnswerTool()
74
+
75
+ # 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:
76
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
77
+
78
+ model = HfApiModel(
79
+ max_tokens=2096,
80
+ temperature=0.5,
81
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
82
+ custom_role_conversions=None,
83
+ )
84
+
85
+
86
+ # Import tool from Hub
87
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
88
+
89
+ with open("prompts.yaml", 'r') as stream:
90
+ prompt_templates = yaml.safe_load(stream)
91
+
92
+ agent = CodeAgent(
93
+ model=model,
94
+ tools=[final_answer], ## add your tools here (don't remove final answer)
95
+ max_steps=6,
96
+ verbosity_level=1,
97
+ grammar=None,
98
+ planning_interval=None,
99
+ name=None,
100
+ description=None,
101
+ prompt_templates=prompt_templates
102
+ )
103
+
104
+
105
+ GradioUI(agent).launch()
106
 
107
  @tool
108
  def get_current_time_in_timezone(timezone: str) -> str: