spagestic commited on
Commit
c6a39bf
ยท
1 Parent(s): 7ac0d56

feat: enhance arithmetic interfaces with detailed descriptions and examples

Browse files
maths/arithmetic/add.py CHANGED
@@ -14,5 +14,6 @@ add_interface = gr.Interface(
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Addition",
17
- description="Add two numbers"
 
18
  )
 
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Addition",
17
+ description="Add two numbers.\n\n**Description:**\nThis tool takes two numbers as input and returns their sum.\n\n**Examples:**\n- Input: 2, 3 โ†’ Output: 5\n- Input: -1.5, 4.2 โ†’ Output: 2.7\n- Input: 0, 0 โ†’ Output: 0",
18
+ examples=[[2, 3], [-1.5, 4.2], [0, 0]],
19
  )
maths/arithmetic/calculate_array.py CHANGED
@@ -31,13 +31,25 @@ def calculate_array(numbers: list, operations: list) -> float:
31
  raise ValueError(f"Unsupported operation: {op}")
32
  return result
33
 
 
 
 
 
 
 
 
 
 
 
 
34
  array_calc_interface = gr.Interface(
35
- fn=lambda numbers, operations: calculate_array(numbers, operations),
36
  inputs=[
37
  gr.Textbox(label="Numbers (comma-separated, e.g. 2, 3, 4)"),
38
  gr.Textbox(label="Operations (comma-separated, e.g. add, multiply)")
39
  ],
40
  outputs="text",
41
  title="Array Calculation",
42
- description="Calculate a sequence of numbers with specified operations. Example: Numbers: 2, 3, 4; Operations: add, multiply โ†’ (2 + 3) * 4"
 
43
  )
 
31
  raise ValueError(f"Unsupported operation: {op}")
32
  return result
33
 
34
+ def parse_number_list(s):
35
+ try:
36
+ return [float(x.strip()) for x in s.split(',') if x.strip() != '']
37
+ except Exception:
38
+ return []
39
+
40
+ def parse_operation_list(s):
41
+ ops = [x.strip().lower() for x in s.split(',') if x.strip() != '']
42
+ valid_ops = {'add', 'subtract', 'multiply', 'divide'}
43
+ return [op for op in ops if op in valid_ops]
44
+
45
  array_calc_interface = gr.Interface(
46
+ fn=lambda numbers, operations: calculate_array(parse_number_list(numbers), parse_operation_list(operations)),
47
  inputs=[
48
  gr.Textbox(label="Numbers (comma-separated, e.g. 2, 3, 4)"),
49
  gr.Textbox(label="Operations (comma-separated, e.g. add, multiply)")
50
  ],
51
  outputs="text",
52
  title="Array Calculation",
53
+ description="Calculate a sequence of numbers with specified operations.\n\n**Description:**\nThis tool takes a list of numbers and a list of operations (add, subtract, multiply, divide) and computes the result step by step.\n\n**Examples:**\n- Numbers: 2, 3, 4; Operations: add, multiply โ†’ (2 + 3) * 4 = 20\n- Numbers: 10, 2, 3; Operations: subtract, divide โ†’ (10 - 2) / 3 = 2.666...\n- Numbers: 5, 0; Operations: divide โ†’ 5 / 0 = Error: Division by zero",
54
+ examples=[["2, 3, 4", "add, multiply"], ["10, 2, 3", "subtract, divide"], ["5, 0", "divide"]],
55
  )
maths/arithmetic/calculate_array_with_visualization.py CHANGED
@@ -57,5 +57,6 @@ array_calc_vis_interface = gr.Interface(
57
  ],
58
  outputs=[gr.Textbox(label="Result"), gr.Plot(label="Visualization")],
59
  title="Array Calculation with Visualization",
60
- description="Calculate a sequence of numbers with specified operations and see a number line visualization."
 
61
  )
 
57
  ],
58
  outputs=[gr.Textbox(label="Result"), gr.Plot(label="Visualization")],
59
  title="Array Calculation with Visualization",
60
+ description="Calculate a sequence of numbers with specified operations and see a number line visualization.\n\n**Description:**\nThis tool takes a list of numbers and a list of operations (add, subtract, multiply, divide), computes the result step by step, and visualizes the process on a number line.\n\n**Examples:**\n- Numbers: 2, 3, 4; Operations: add, multiply โ†’ (2 + 3) * 4 = 20\n- Numbers: 10, 2, 3; Operations: subtract, divide โ†’ (10 - 2) / 3 = 2.666...\n- Numbers: 5, 0; Operations: divide โ†’ 5 / 0 = Error: Division by zero",
61
+ examples=[["2, 3, 4", "add, multiply"], ["10, 2, 3", "subtract, divide"], ["5, 0", "divide"]],
62
  )
maths/arithmetic/divide.py CHANGED
@@ -16,5 +16,6 @@ divide_interface = gr.Interface(
16
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
17
  outputs="text",
18
  title="Division",
19
- description="Divide two numbers"
 
20
  )
 
16
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
17
  outputs="text",
18
  title="Division",
19
+ description="Divide two numbers.\n\n**Description:**\nThis tool takes two numbers as input and returns the result of dividing A by B.\n\n**Examples:**\n- Input: 6, 3 โ†’ Output: 2\n- Input: 5, 2 โ†’ Output: 2.5\n- Input: 7, 0 โ†’ Output: Error: Division by zero",
20
+ examples=[[6, 3], [5, 2], [7, 0]],
21
  )
maths/arithmetic/multiply.py CHANGED
@@ -14,5 +14,6 @@ multiply_interface = gr.Interface(
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Multiplication",
17
- description="Multiply two numbers"
 
18
  )
 
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Multiplication",
17
+ description="Multiply two numbers.\n\n**Description:**\nThis tool takes two numbers as input and returns their product.\n\n**Examples:**\n- Input: 2, 3 โ†’ Output: 6\n- Input: -1.5, 4 โ†’ Output: -6\n- Input: 0, 5 โ†’ Output: 0",
18
+ examples=[[2, 3], [-1.5, 4], [0, 5]],
19
  )
maths/arithmetic/subtract.py CHANGED
@@ -14,5 +14,6 @@ subtract_interface = gr.Interface(
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Subtraction",
17
- description="Subtract two numbers"
 
18
  )
 
14
  inputs=[gr.Number(label="A"), gr.Number(label="B")],
15
  outputs="number",
16
  title="Subtraction",
17
+ description="Subtract two numbers.\n\n**Description:**\nThis tool takes two numbers as input and returns their difference (A - B).\n\n**Examples:**\n- Input: 5, 3 โ†’ Output: 2\n- Input: -1.5, 4.2 โ†’ Output: -5.7\n- Input: 0, 0 โ†’ Output: 0",
18
+ examples=[[5, 3], [-1.5, 4.2], [0, 0]],
19
  )