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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -28
app.py CHANGED
@@ -43,38 +43,28 @@ def create_quickchart_graph(equations: list[str]) -> str:
43
  if len(equations) > 2:
44
  return "I can only generate for two equations."
45
 
46
- datasets = []
 
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}"
79
 
80
 
 
43
  if len(equations) > 2:
44
  return "I can only generate for two equations."
45
 
46
+ # Build the parameters for the /chart/formula endpoint
47
+ params = []
48
  colors = ["blue", "red"]
49
+
50
  for idx, equation in enumerate(equations):
51
+ if idx >= 2: # Limit to 2 equations
52
+ return "I can only generate graphs for up to two equations."
53
+
54
+ # Extract the right side of the equation if it has an equals sign
55
  if '=' in equation:
56
  function_part = equation.split('=')[1].strip()
57
+ else:
58
+ function_part = equation.strip()
59
+
60
+ # Add this equation to the parameters
61
+ params.append(f"f{idx+1}={urllib.parse.quote(function_part)}")
62
+ params.append(f"c{idx+1}={colors[idx]}")
63
+
64
+ # Create the formula URL with parameters
65
+ param_string = "&".join(params)
66
+ url = f"https://quickchart.io/chart/formula?{param_string}&width=500&height=300"
67
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  return f"Here is your QuickChart.io graph: {url}"
69
 
70