IshfatAbrar commited on
Commit
aa07a00
·
verified ·
1 Parent(s): 4a23a3c

formatted JSON structure

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -5,6 +5,7 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import urllib.parse
 
8
 
9
  from Gradio_UI import GradioUI
10
 
@@ -34,10 +35,8 @@ def reverse_and_repeat(text: str, repeat: int) -> str:
34
  @tool
35
  def create_quickchart_graph(equations: list[str]) -> str:
36
  """Creates a QuickChart.io graph link for up to two mathematical equations.
37
-
38
  Args:
39
  equations: A list containing up to two mathematical equations as strings (e.g., ['y = x^2', 'y = sin(x)']).
40
-
41
  Returns:
42
  A URL string to the QuickChart.io graph displaying the given equations, or an error message if more than two equations are provided.
43
  """
@@ -48,24 +47,32 @@ def create_quickchart_graph(equations: list[str]) -> str:
48
  colors = ["blue", "red"]
49
 
50
  for idx, equation in enumerate(equations):
51
- function_part = equation.split('=')[1].strip()
52
- datasets.append({
53
- "fn": function_part,
54
- "label": equation,
55
- "borderColor": colors[idx]
56
- })
 
 
 
57
 
58
  chart_config = {
59
- "type": "line",
60
  "data": {"datasets": datasets},
61
  "options": {
 
 
 
 
62
  "scales": {
63
- "xAxes": [{"type": "linear", "position": "bottom"}]
 
64
  }
65
  }
66
  }
67
 
68
- encoded_chart = urllib.parse.quote(str(chart_config))
69
  url = f"https://quickchart.io/chart?c={encoded_chart}"
70
 
71
  return f"Here is your QuickChart.io graph: {url}"
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import urllib.parse
8
+ import json
9
 
10
  from Gradio_UI import GradioUI
11
 
 
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
  """
 
47
  colors = ["blue", "red"]
48
 
49
  for idx, equation in enumerate(equations):
50
+ if '=' in equation:
51
+ function_part = equation.split('=')[1].strip()
52
+ datasets.append({
53
+ "fn": function_part,
54
+ "graphType": "function",
55
+ "label": equation,
56
+ "borderColor": colors[idx],
57
+ "fill": False
58
+ })
59
 
60
  chart_config = {
61
+ "type": "functionPlot",
62
  "data": {"datasets": datasets},
63
  "options": {
64
+ "title": {
65
+ "display": True,
66
+ "text": "Function Graph"
67
+ },
68
  "scales": {
69
+ "xAxes": [{"type": "linear", "position": "bottom", "ticks": {"min": -10, "max": 10}}],
70
+ "yAxes": [{"ticks": {"min": -10, "max": 10}}]
71
  }
72
  }
73
  }
74
 
75
+ encoded_chart = urllib.parse.quote(json.dumps(chart_config))
76
  url = f"https://quickchart.io/chart?c={encoded_chart}"
77
 
78
  return f"Here is your QuickChart.io graph: {url}"