IshfatAbrar commited on
Commit
1d5e7c6
·
verified ·
1 Parent(s): ec56408

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -37
app.py CHANGED
@@ -33,53 +33,94 @@ def reverse_and_repeat(text: str, repeat: int) -> str:
33
 
34
 
35
  @tool
36
- def create_quickchart_graph(equations: list[str]) -> str:
37
- """Creates a QuickChart.io graph link for up to two mathematical equations.
38
  Args:
39
- equations: A list containing up to two mathematical equations as strings (e.g., ['y = x^2', 'y = sin(x)']).
 
40
  Returns:
41
- A URL string to the QuickChart.io graph displaying the given equations, or an error message if more than two equations are provided.
42
  """
43
- if len(equations) > 2:
44
- return "I can only generate for two equations."
45
-
46
- # Extract the right side of each equation
47
- functions = []
48
- for eq in equations:
49
- if '=' in eq:
50
- function_part = eq.split('=')[1].strip()
51
- else:
52
- function_part = eq.strip()
53
- functions.append(function_part)
54
 
55
- # Build the formula URL
56
- base_url = "https://quickchart.io/chart"
57
- chart_type = "formula"
58
 
59
- # For the formula endpoint, we need to encode the entire formula
60
- url_params = {
61
- "c": {
62
- "type": chart_type,
63
- "data": {
64
- "functions": functions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  },
66
- "options": {
67
- "title": {
68
- "display": True,
69
- "text": "Function Plot"
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
- },
73
- "width": 500,
74
- "height": 300
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  # Convert to JSON and URL encode
78
- import json
79
- encoded_params = urllib.parse.quote(json.dumps(url_params))
80
- url = f"{base_url}?c={encoded_params}"
81
 
82
- return f"Here is your QuickChart.io graph: {url}"
83
 
84
 
85
 
@@ -124,7 +165,7 @@ agent = CodeAgent(
124
  tools=[final_answer,
125
  image_generation_tool,
126
  reverse_and_repeat,
127
- create_quickchart_graph
128
  ], ## add your tools here (don't remove final answer)
129
  max_steps=6,
130
  verbosity_level=1,
 
33
 
34
 
35
  @tool
36
+ def search_and_graph_cricket_rankings(teams: list[str], years: int = 5) -> str:
37
+ """Searches for cricket rankings of specified teams over a period of years and generates a graph.
38
  Args:
39
+ teams: List of team names to search for (e.g., ['Bangladesh', 'India'])
40
+ years: Number of recent years to include in the graph (default: 5)
41
  Returns:
42
+ A URL string to a QuickChart.io graph showing the ranking trends
43
  """
44
+ if not teams:
45
+ return "Please provide at least one team name."
 
 
 
 
 
 
 
 
 
46
 
47
+ # Initialize DuckDuckGo search tool
48
+ search_tool = DuckDuckGoSearchTool()
 
49
 
50
+ # Get current year
51
+ current_year = datetime.datetime.now().year
52
+ years_range = list(range(current_year - years + 1, current_year + 1))
53
+
54
+ # Collect data for each team
55
+ team_data = {}
56
+ for team in teams:
57
+ rankings = []
58
+ for year in years_range:
59
+ # Search for ranking data
60
+ search_query = f"{team} cricket team ICC ranking {year}"
61
+ search_results = search_tool(search_query)
62
+
63
+ # In a real implementation, you would parse the search results to extract the actual ranking
64
+ # For this demo, we'll generate random rankings between 1-10
65
+ # This should be replaced with actual parsing logic
66
+ import random
67
+ ranking = random.randint(1, 10)
68
+ rankings.append(ranking)
69
+
70
+ team_data[team] = rankings
71
+
72
+ # Create the chart configuration
73
+ chart_config = {
74
+ "type": "line",
75
+ "data": {
76
+ "labels": [str(year) for year in years_range],
77
+ "datasets": []
78
+ },
79
+ "options": {
80
+ "title": {
81
+ "display": True,
82
+ "text": "Cricket Team Rankings Over Time"
83
  },
84
+ "scales": {
85
+ "yAxes": [{
86
+ "ticks": {
87
+ "reverse": True, # Lower number is better for rankings
88
+ "min": 1,
89
+ "max": 10
90
+ },
91
+ "scaleLabel": {
92
+ "display": True,
93
+ "labelString": "Ranking"
94
+ }
95
+ }],
96
+ "xAxes": [{
97
+ "scaleLabel": {
98
+ "display": True,
99
+ "labelString": "Year"
100
+ }
101
+ }]
102
  }
103
+ }
 
 
104
  }
105
 
106
+ # Colors for different teams
107
+ colors = ["blue", "green", "red", "orange", "purple"]
108
+
109
+ # Add each team's data to the chart
110
+ for i, (team, rankings) in enumerate(team_data.items()):
111
+ dataset = {
112
+ "label": f"{team}",
113
+ "data": rankings,
114
+ "fill": False,
115
+ "borderColor": colors[i % len(colors)]
116
+ }
117
+ chart_config["data"]["datasets"].append(dataset)
118
+
119
  # Convert to JSON and URL encode
120
+ encoded_chart = urllib.parse.quote(json.dumps(chart_config))
121
+ url = f"https://quickchart.io/chart?c={encoded_chart}"
 
122
 
123
+ return f"Here is the cricket ranking chart for {', '.join(teams)}: {url}"
124
 
125
 
126
 
 
165
  tools=[final_answer,
166
  image_generation_tool,
167
  reverse_and_repeat,
168
+ search_and_graph_cricket_rankings
169
  ], ## add your tools here (don't remove final answer)
170
  max_steps=6,
171
  verbosity_level=1,