Spaces:
Runtime error
Runtime error
moved interfaces for arithmetic, algebra, trigonometry, and calculus to separate files
Browse files
app.py
CHANGED
@@ -1,112 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
from utils.
|
3 |
-
from maths.elementary.
|
4 |
-
from maths.middleschool.
|
5 |
-
from maths.highschool.
|
6 |
-
from maths.university.
|
7 |
-
|
8 |
-
# Text Utils Tab
|
9 |
-
letter_counter_interface = gr.Interface(
|
10 |
-
fn=letter_counter,
|
11 |
-
inputs=["text", "text"],
|
12 |
-
outputs="number",
|
13 |
-
title="Letter Counter",
|
14 |
-
description="Count how many times a letter appears in a word"
|
15 |
-
)
|
16 |
-
|
17 |
-
# Elementary Math Tab
|
18 |
-
add_interface = gr.Interface(
|
19 |
-
fn=add,
|
20 |
-
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
21 |
-
outputs="number",
|
22 |
-
title="Addition",
|
23 |
-
description="Add two numbers"
|
24 |
-
)
|
25 |
-
|
26 |
-
subtract_interface = gr.Interface(
|
27 |
-
fn=subtract,
|
28 |
-
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
29 |
-
outputs="number",
|
30 |
-
title="Subtraction",
|
31 |
-
description="Subtract two numbers"
|
32 |
-
)
|
33 |
-
|
34 |
-
multiply_interface = gr.Interface(
|
35 |
-
fn=multiply,
|
36 |
-
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
37 |
-
outputs="number",
|
38 |
-
title="Multiplication",
|
39 |
-
description="Multiply two numbers"
|
40 |
-
)
|
41 |
-
|
42 |
-
divide_interface = gr.Interface(
|
43 |
-
fn=divide,
|
44 |
-
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
45 |
-
outputs="text",
|
46 |
-
title="Division",
|
47 |
-
description="Divide two numbers"
|
48 |
-
)
|
49 |
-
|
50 |
-
# Middle School Math Tab
|
51 |
-
solve_linear_equation_interface = gr.Interface(
|
52 |
-
fn=solve_linear_equation,
|
53 |
-
inputs=[
|
54 |
-
gr.Number(label="Coefficient (a)"),
|
55 |
-
gr.Number(label="Constant (b)")
|
56 |
-
],
|
57 |
-
outputs="text",
|
58 |
-
title="Linear Equation Solver",
|
59 |
-
description="Solve the equation ax = b for x"
|
60 |
-
)
|
61 |
-
|
62 |
-
evaluate_expression_interface = gr.Interface(
|
63 |
-
fn=evaluate_expression,
|
64 |
-
inputs=[
|
65 |
-
gr.Number(label="a (coefficient of x²)"),
|
66 |
-
gr.Number(label="b (coefficient of x)"),
|
67 |
-
gr.Number(label="c (constant)"),
|
68 |
-
gr.Number(label="x (value)")
|
69 |
-
],
|
70 |
-
outputs="number",
|
71 |
-
title="Quadratic Expression Evaluator",
|
72 |
-
description="Evaluate ax² + bx + c for a given value of x"
|
73 |
-
)
|
74 |
-
|
75 |
-
# High School Math Tab
|
76 |
-
trig_interface = gr.Interface(
|
77 |
-
fn=lambda angle, function: {
|
78 |
-
"sin": sin_degrees(angle),
|
79 |
-
"cos": cos_degrees(angle),
|
80 |
-
"tan": tan_degrees(angle)
|
81 |
-
}[function],
|
82 |
-
inputs=[
|
83 |
-
gr.Number(label="Angle (degrees)"),
|
84 |
-
gr.Radio(["sin", "cos", "tan"], label="Trigonometric Function")
|
85 |
-
],
|
86 |
-
outputs="number",
|
87 |
-
title="Trigonometry Calculator",
|
88 |
-
description="Calculate trigonometric functions for angles in degrees"
|
89 |
-
)
|
90 |
-
|
91 |
-
# University Math Tab
|
92 |
-
derivative_interface = gr.Interface(
|
93 |
-
fn=lambda coefficients: derivative_polynomial([float(c) for c in coefficients.split(',')]),
|
94 |
-
inputs=gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
|
95 |
-
outputs="json",
|
96 |
-
title="Polynomial Derivative",
|
97 |
-
description="Find the derivative of a polynomial function"
|
98 |
-
)
|
99 |
-
|
100 |
-
integral_interface = gr.Interface(
|
101 |
-
fn=lambda coefficients, c: integral_polynomial([float(x) for x in coefficients.split(',')], float(c)),
|
102 |
-
inputs=[
|
103 |
-
gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
|
104 |
-
gr.Number(label="Integration Constant (c)", value=0)
|
105 |
-
],
|
106 |
-
outputs="json",
|
107 |
-
title="Polynomial Integration",
|
108 |
-
description="Find the indefinite integral of a polynomial function"
|
109 |
-
)
|
110 |
|
111 |
# Group interfaces by education level
|
112 |
elementary_tab = gr.TabbedInterface(
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils.text_utils_interface import letter_counter_interface
|
3 |
+
from maths.elementary.arithmetic_interface import add_interface, subtract_interface, multiply_interface, divide_interface
|
4 |
+
from maths.middleschool.algebra_interface import solve_linear_equation_interface, evaluate_expression_interface
|
5 |
+
from maths.highschool.trigonometry_interface import trig_interface
|
6 |
+
from maths.university.calculus_interface import derivative_interface, integral_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Group interfaces by education level
|
9 |
elementary_tab = gr.TabbedInterface(
|
maths/elementary/arithmetic_interface.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from maths.elementary.arithmetic import add, subtract, multiply, divide
|
3 |
+
|
4 |
+
# Elementary Math Tab
|
5 |
+
add_interface = gr.Interface(
|
6 |
+
fn=add,
|
7 |
+
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
8 |
+
outputs="number",
|
9 |
+
title="Addition",
|
10 |
+
description="Add two numbers"
|
11 |
+
)
|
12 |
+
|
13 |
+
subtract_interface = gr.Interface(
|
14 |
+
fn=subtract,
|
15 |
+
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
16 |
+
outputs="number",
|
17 |
+
title="Subtraction",
|
18 |
+
description="Subtract two numbers"
|
19 |
+
)
|
20 |
+
|
21 |
+
multiply_interface = gr.Interface(
|
22 |
+
fn=multiply,
|
23 |
+
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
24 |
+
outputs="number",
|
25 |
+
title="Multiplication",
|
26 |
+
description="Multiply two numbers"
|
27 |
+
)
|
28 |
+
|
29 |
+
divide_interface = gr.Interface(
|
30 |
+
fn=divide,
|
31 |
+
inputs=[gr.Number(label="A"), gr.Number(label="B")],
|
32 |
+
outputs="text",
|
33 |
+
title="Division",
|
34 |
+
description="Divide two numbers"
|
35 |
+
)
|
maths/highschool/trigonometry_interface.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from maths.highschool.trigonometry import sin_degrees, cos_degrees, tan_degrees
|
3 |
+
|
4 |
+
# High School Math Tab
|
5 |
+
trig_interface = gr.Interface(
|
6 |
+
fn=lambda angle, function: {
|
7 |
+
"sin": sin_degrees(angle),
|
8 |
+
"cos": cos_degrees(angle),
|
9 |
+
"tan": tan_degrees(angle)
|
10 |
+
}[function],
|
11 |
+
inputs=[
|
12 |
+
gr.Number(label="Angle (degrees)"),
|
13 |
+
gr.Radio(["sin", "cos", "tan"], label="Trigonometric Function")
|
14 |
+
],
|
15 |
+
outputs="number",
|
16 |
+
title="Trigonometry Calculator",
|
17 |
+
description="Calculate trigonometric functions for angles in degrees"
|
18 |
+
)
|
maths/middleschool/algebra_interface.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from maths.middleschool.algebra import solve_linear_equation, evaluate_expression
|
3 |
+
|
4 |
+
# Middle School Math Tab
|
5 |
+
solve_linear_equation_interface = gr.Interface(
|
6 |
+
fn=solve_linear_equation,
|
7 |
+
inputs=[
|
8 |
+
gr.Number(label="Coefficient (a)"),
|
9 |
+
gr.Number(label="Constant (b)")
|
10 |
+
],
|
11 |
+
outputs="text",
|
12 |
+
title="Linear Equation Solver",
|
13 |
+
description="Solve the equation ax = b for x"
|
14 |
+
)
|
15 |
+
|
16 |
+
evaluate_expression_interface = gr.Interface(
|
17 |
+
fn=evaluate_expression,
|
18 |
+
inputs=[
|
19 |
+
gr.Number(label="a (coefficient of x²)"),
|
20 |
+
gr.Number(label="b (coefficient of x)"),
|
21 |
+
gr.Number(label="c (constant)"),
|
22 |
+
gr.Number(label="x (value)")
|
23 |
+
],
|
24 |
+
outputs="number",
|
25 |
+
title="Quadratic Expression Evaluator",
|
26 |
+
description="Evaluate ax² + bx + c for a given value of x"
|
27 |
+
)
|
maths/university/calculus_interface.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from maths.university.calculus import derivative_polynomial, integral_polynomial
|
3 |
+
|
4 |
+
# University Math Tab
|
5 |
+
derivative_interface = gr.Interface(
|
6 |
+
fn=lambda coefficients: derivative_polynomial([float(c) for c in coefficients.split(',')]),
|
7 |
+
inputs=gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
|
8 |
+
outputs="json",
|
9 |
+
title="Polynomial Derivative",
|
10 |
+
description="Find the derivative of a polynomial function"
|
11 |
+
)
|
12 |
+
|
13 |
+
integral_interface = gr.Interface(
|
14 |
+
fn=lambda coefficients, c: integral_polynomial([float(x) for x in coefficients.split(',')], float(c)),
|
15 |
+
inputs=[
|
16 |
+
gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
|
17 |
+
gr.Number(label="Integration Constant (c)", value=0)
|
18 |
+
],
|
19 |
+
outputs="json",
|
20 |
+
title="Polynomial Integration",
|
21 |
+
description="Find the indefinite integral of a polynomial function"
|
22 |
+
)
|
utils/text_utils_interface.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from utils.text_utils import letter_counter
|
3 |
+
|
4 |
+
# Text Utils Tab
|
5 |
+
letter_counter_interface = gr.Interface(
|
6 |
+
fn=letter_counter,
|
7 |
+
inputs=["text", "text"],
|
8 |
+
outputs="number",
|
9 |
+
title="Letter Counter",
|
10 |
+
description="Count how many times a letter appears in a word"
|
11 |
+
)
|