Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import math
|
3 |
-
from fractions import Fraction
|
4 |
|
5 |
-
|
6 |
-
def calculator(num1, operation, num2=None, num3=None, num4=None):
|
7 |
if operation == "add":
|
8 |
return num1 + num2
|
9 |
elif operation == "subtract":
|
@@ -17,25 +15,23 @@ def calculator(num1, operation, num2=None, num3=None, num4=None):
|
|
17 |
elif operation == "cube":
|
18 |
return num1 * num1 * num1
|
19 |
elif operation == "exponential":
|
20 |
-
return math.pow(num1, num2)
|
21 |
elif operation == "frac add":
|
22 |
-
return
|
23 |
elif operation == "frac subtract":
|
24 |
-
return
|
25 |
elif operation == "frac multiply":
|
26 |
-
return
|
27 |
elif operation == "frac divide":
|
28 |
-
return
|
29 |
-
|
30 |
|
|
|
31 |
demo = gr.Interface(
|
32 |
fn=calculator,
|
33 |
inputs=[
|
34 |
gr.Number(value=4),
|
35 |
gr.Radio(["add", "subtract", "multiply", "divide", "square", "cube", "exponential", "frac add", "frac subtract", "frac multiply", "frac divide"]),
|
36 |
-
gr.Number(value=2, label="Second Number (optional)", optional=True)
|
37 |
-
gr.Number(value=3, label="Third Number (optional)", optional=True),
|
38 |
-
gr.Number(value=4, label="Fourth Number (optional)", optional=True)
|
39 |
],
|
40 |
outputs="number",
|
41 |
examples=[
|
@@ -44,13 +40,13 @@ demo = gr.Interface(
|
|
44 |
[-4, "multiply", 2.5],
|
45 |
[0, "subtract", 1.2],
|
46 |
[2, "exponential", 3],
|
47 |
-
[1, "frac
|
48 |
-
[
|
49 |
-
[
|
50 |
-
[1, "frac divide", 2
|
51 |
],
|
52 |
-
title="Scientific
|
53 |
-
description="Here's a sample scientific
|
54 |
)
|
55 |
|
56 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import math
|
|
|
3 |
|
4 |
+
def calculator(num1, operation, num2=None):
|
|
|
5 |
if operation == "add":
|
6 |
return num1 + num2
|
7 |
elif operation == "subtract":
|
|
|
15 |
elif operation == "cube":
|
16 |
return num1 * num1 * num1
|
17 |
elif operation == "exponential":
|
18 |
+
return math.pow(num1, num2)
|
19 |
elif operation == "frac add":
|
20 |
+
return num1 + num2
|
21 |
elif operation == "frac subtract":
|
22 |
+
return num1 - num2
|
23 |
elif operation == "frac multiply":
|
24 |
+
return num1 * num2
|
25 |
elif operation == "frac divide":
|
26 |
+
return num1 / num2
|
|
|
27 |
|
28 |
+
|
29 |
demo = gr.Interface(
|
30 |
fn=calculator,
|
31 |
inputs=[
|
32 |
gr.Number(value=4),
|
33 |
gr.Radio(["add", "subtract", "multiply", "divide", "square", "cube", "exponential", "frac add", "frac subtract", "frac multiply", "frac divide"]),
|
34 |
+
gr.Number(value=2, label="Second Number (optional)", optional=True)
|
|
|
|
|
35 |
],
|
36 |
outputs="number",
|
37 |
examples=[
|
|
|
40 |
[-4, "multiply", 2.5],
|
41 |
[0, "subtract", 1.2],
|
42 |
[2, "exponential", 3],
|
43 |
+
[1/2, "frac multiply", 3/4],
|
44 |
+
[5/6, "frac add", 2/3],
|
45 |
+
[7/8, "frac subtract", 1/4],
|
46 |
+
[1/3, "frac divide", 2/5]
|
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()
|