Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
def calculator(num1, operation, num2=None):
|
5 |
if operation == "add":
|
6 |
-
|
7 |
elif operation == "subtract":
|
8 |
-
|
9 |
elif operation == "multiply":
|
10 |
-
|
11 |
elif operation == "divide":
|
12 |
-
|
13 |
elif operation == "square":
|
14 |
-
|
15 |
elif operation == "cube":
|
16 |
-
|
17 |
elif operation == "exponential":
|
18 |
-
|
19 |
elif operation == "frac add":
|
20 |
-
|
21 |
elif operation == "frac subtract":
|
22 |
-
|
23 |
elif operation == "frac multiply":
|
24 |
-
|
25 |
elif operation == "frac divide":
|
26 |
-
|
|
|
27 |
|
28 |
-
|
29 |
demo = gr.Interface(
|
30 |
fn=calculator,
|
31 |
inputs=[
|
@@ -40,13 +40,13 @@ demo = gr.Interface(
|
|
40 |
[-4, "multiply", 2.5],
|
41 |
[0, "subtract", 1.2],
|
42 |
[2, "exponential", 3],
|
43 |
-
[
|
44 |
-
[
|
45 |
-
[
|
46 |
-
[
|
47 |
],
|
48 |
title="Scientific Calculator",
|
49 |
-
description="Here's a sample scientific calculator. Enjoy! Code by: Freddy Aboulton Improved by: Usually3"
|
50 |
)
|
51 |
|
52 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from fractions import Fraction
|
3 |
|
4 |
def calculator(num1, operation, num2=None):
|
5 |
if operation == "add":
|
6 |
+
result = Fraction(num1) + Fraction(num2)
|
7 |
elif operation == "subtract":
|
8 |
+
result = Fraction(num1) - Fraction(num2)
|
9 |
elif operation == "multiply":
|
10 |
+
result = Fraction(num1) * Fraction(num2)
|
11 |
elif operation == "divide":
|
12 |
+
result = Fraction(num1) / Fraction(num2)
|
13 |
elif operation == "square":
|
14 |
+
result = Fraction(num1) * Fraction(num1)
|
15 |
elif operation == "cube":
|
16 |
+
result = Fraction(num1) * Fraction(num1) * Fraction(num1)
|
17 |
elif operation == "exponential":
|
18 |
+
result = pow(Fraction(num1), Fraction(num2))
|
19 |
elif operation == "frac add":
|
20 |
+
result = Fraction(num1) + Fraction(num2)
|
21 |
elif operation == "frac subtract":
|
22 |
+
result = Fraction(num1) - Fraction(num2)
|
23 |
elif operation == "frac multiply":
|
24 |
+
result = Fraction(num1) * Fraction(num2)
|
25 |
elif operation == "frac divide":
|
26 |
+
result = Fraction(num1) / Fraction(num2)
|
27 |
+
return result
|
28 |
|
|
|
29 |
demo = gr.Interface(
|
30 |
fn=calculator,
|
31 |
inputs=[
|
|
|
40 |
[-4, "multiply", 2.5],
|
41 |
[0, "subtract", 1.2],
|
42 |
[2, "exponential", 3],
|
43 |
+
[Fraction(3, 4), "frac add", Fraction(1, 4)],
|
44 |
+
[Fraction(3, 4), "frac subtract", Fraction(1, 4)],
|
45 |
+
[Fraction(3, 4), "frac multiply", Fraction(1, 4)],
|
46 |
+
[Fraction(3, 4), "frac divide", Fraction(1, 4)],
|
47 |
],
|
48 |
title="Scientific Calculator",
|
49 |
+
description="Here's a sample scientific calculator. Enjoy! Code by: Freddy Aboulton Improved by: Usually3 and ChatGpt"
|
50 |
)
|
51 |
|
52 |
demo.launch()
|