nangelov commited on
Commit
bdf1a29
·
verified ·
1 Parent(s): e42b0dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
 
3
  import requests
4
  import pytz
5
  import yaml
@@ -10,17 +11,80 @@ from Gradio_UI import GradioUI
10
  import os
11
  from huggingface_hub import login
12
  login(token = os.getenv('nangelov_hf_token'))
 
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
17
- #Keep this format for the description / args / args description but feel free to modify the tool
18
- """A tool that does nothing yet
 
 
 
 
 
19
  Args:
20
- arg1: the first argument
21
- arg2: the second argument
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  """
23
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
+ from datetime import date
4
  import requests
5
  import pytz
6
  import yaml
 
11
  import os
12
  from huggingface_hub import login
13
  login(token = os.getenv('nangelov_hf_token'))
14
+ FOOTBALL_DATA_TOKEN = os.getenv('football-data-token')
15
 
16
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
17
  @tool
18
+ def getCompetitionInitials(competition: str) -> str:
19
+ """
20
+ Returns the competition initials (code) for a given competition name.
21
+
22
+ Example usage:
23
+ competitionCode = getCompetitionInitials("Premier League") # Output: PL
24
+ competitionCode = getCompetitionInitials("Bundesliga") # Output: BL1
25
+
26
  Args:
27
+ competition (str): The full name of the competition.
28
+
29
+ Returns:
30
+ str: The competition code if found, otherwise None.
31
+ """
32
+ competitions = {
33
+ "WC": "FIFA World Cup",
34
+ "CL": "UEFA Champions League",
35
+ "BL1": "Bundesliga",
36
+ "DED": "Eredivisie",
37
+ "BSA": "Campeonato Brasileiro Série A",
38
+ "PD": "Primera Division",
39
+ "FL1": "Ligue 1",
40
+ "ELC": "Championship",
41
+ "PPL": "Primeira Liga",
42
+ "EC": "European Championship",
43
+ "SA": "Serie A",
44
+ "PL": "Premier League"
45
+ }
46
+
47
+ # Iterate through the dictionary to find the matching competition name.
48
+ for code, name in competitions.items():
49
+ if name.lower() == competition.lower():
50
+ return code
51
+ # Return None if no match is found.
52
+ return None
53
+
54
+ @tool
55
+ @tool
56
+ def getCompetitionMatchesResultsByDate(competitionInitials: str, match_date: date) -> dict:
57
  """
58
+ Gets football match results for a given competition on a specified date.
59
+
60
+ Args:
61
+ competitionInitials (str): The code of the competition (e.g., 'PL' for Premier League).
62
+ match_date (date): The date for which to retrieve match results.
63
+
64
+ Returns:
65
+ dict: The JSON response from the API if successful, or an error message.
66
+ """
67
+ # Format the date as needed by the API (e.g., YYYY-MM-DD)
68
+ date_str = match_date.isoformat() # converts date to 'YYYY-MM-DD'
69
+
70
+ # Create the URL using an f-string
71
+ url = f'https://api.football-data.org/v4/competitions/{competitionInitials}/matches?date={date_str}'
72
+
73
+ # Set up the headers with your API token.
74
+ headers = {
75
+ 'X-Auth-Token': FOOTBALL_DATA_TOKEN
76
+ }
77
+
78
+ # Make the request
79
+ response = requests.get(url, headers=headers)
80
+
81
+ # Check if the request was successful.
82
+ if response.status_code == 200:
83
+ data = response.json() # Parse the JSON response.
84
+ return data
85
+ else:
86
+ # Return error details as a dict
87
+ return {"error": response.status_code, "message": response.text}
88
 
89
  @tool
90
  def get_current_time_in_timezone(timezone: str) -> str: