Usually3 commited on
Commit
14f0522
·
1 Parent(s): 9f72ed4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,31 +1,31 @@
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":
8
- return num1 - num2
9
  elif operation == "multiply":
10
- return num1 * num2
11
  elif operation == "divide":
12
- return num1 / num2
13
  elif operation == "square":
14
- return num1 * num1
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=[
@@ -40,13 +40,13 @@ demo = gr.Interface(
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()
 
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()