srkdev384 commited on
Commit
598d669
·
verified ·
1 Parent(s): 3038fdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -1
app.py CHANGED
@@ -7,6 +7,10 @@ from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
  from smolagents.agent_types import AgentImage
9
  import uuid
 
 
 
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
@@ -53,6 +57,73 @@ def get_current_time_in_timezone(timezone: str) -> str:
53
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
54
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  final_answer = FinalAnswerTool()
57
 
58
  # 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:
@@ -72,7 +143,7 @@ with open("prompts.yaml", 'r') as stream:
72
 
73
  agent = CodeAgent(
74
  model=model,
75
- tools=[final_answer, generate_image, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,
 
7
  from Gradio_UI import GradioUI
8
  from smolagents.agent_types import AgentImage
9
  import uuid
10
+ import requests
11
+ import os
12
+
13
+ CRICKET_API_KEY = os.getenv("CRICKET_API_KEY")
14
 
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
  @tool
 
57
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
58
 
59
 
60
+ @tool
61
+ def get_live_cricket_score(team: str) -> str:
62
+ """
63
+ Fetches live cricket score for a given team.
64
+
65
+ Args:
66
+ team: Name of the cricket team (e.g., India, Australia).
67
+
68
+ Returns:
69
+ Live match details as formatted string.
70
+ """
71
+
72
+ url = "https://api.cricapi.com/v1/currentMatches"
73
+
74
+ params = {
75
+ "apikey": CRICKET_API_KEY,
76
+ "offset": 0
77
+ }
78
+
79
+ response = requests.get(url, params=params)
80
+ data = response.json()
81
+
82
+ if data.get("status") != "success":
83
+ return "Unable to fetch live matches at the moment."
84
+
85
+ matches = data.get("data", [])
86
+
87
+ for match in matches:
88
+ if team.lower() in match["name"].lower():
89
+ return f"""
90
+ Match: {match['name']}
91
+ Status: {match['status']}
92
+ Score: {match.get('score', 'Score not available')}
93
+ """
94
+
95
+ return f"No live match found for {team} right now."
96
+
97
+
98
+ @tool
99
+ def get_today_matches() -> str:
100
+ """
101
+ Fetches all current live cricket matches.
102
+ """
103
+
104
+ url = "https://api.cricapi.com/v1/currentMatches"
105
+
106
+ params = {
107
+ "apikey": CRICKET_API_KEY,
108
+ "offset": 0
109
+ }
110
+
111
+ response = requests.get(url, params=params)
112
+ data = response.json()
113
+
114
+ if data.get("status") != "success":
115
+ return "Unable to fetch matches."
116
+
117
+ matches = data.get("data", [])
118
+
119
+ result = "Today's Matches:\n\n"
120
+
121
+ for match in matches:
122
+ result += f"{match['name']} — {match['status']}\n"
123
+
124
+ return result
125
+
126
+
127
  final_answer = FinalAnswerTool()
128
 
129
  # 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:
 
143
 
144
  agent = CodeAgent(
145
  model=model,
146
+ tools=[final_answer, generate_image, get_current_time_in_timezone, get_live_cricket_score, get_today_matches], ## add your tools here (don't remove final answer)
147
  max_steps=6,
148
  verbosity_level=1,
149
  grammar=None,