Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import math
|
| 3 |
|
| 4 |
-
def calculator(num1, operation, num2):
|
| 5 |
if operation == "add":
|
| 6 |
return num1 + num2
|
| 7 |
elif operation == "subtract":
|
|
@@ -16,13 +16,27 @@ def calculator(num1, operation, num2):
|
|
| 16 |
return num1 * num1 * num1
|
| 17 |
elif operation == "exponential":
|
| 18 |
return math.pow(num1, num2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=calculator,
|
| 22 |
inputs=[
|
| 23 |
gr.Number(value=4),
|
| 24 |
-
gr.Radio(["add", "subtract", "multiply", "divide", "square", "cube", "exponential"]),
|
| 25 |
-
gr.Number(value=2)
|
| 26 |
],
|
| 27 |
outputs="number",
|
| 28 |
examples=[
|
|
@@ -30,7 +44,14 @@ demo = gr.Interface(
|
|
| 30 |
[4, "divide", 2],
|
| 31 |
[-4, "multiply", 2.5],
|
| 32 |
[0, "subtract", 1.2],
|
| 33 |
-
[2, "exponential", 3]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
],
|
| 35 |
title="Scientific Calculator",
|
| 36 |
description="Here's a sample scientific calculator. Enjoy! Code by: Freddy Aboulton Improved by: Usually3"
|
|
|
|
| 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":
|
|
|
|
| 16 |
return num1 * num1 * num1
|
| 17 |
elif operation == "exponential":
|
| 18 |
return math.pow(num1, num2)
|
| 19 |
+
elif operation == "sin":
|
| 20 |
+
return math.sin(num1)
|
| 21 |
+
elif operation == "cos":
|
| 22 |
+
return math.cos(num1)
|
| 23 |
+
elif operation == "tan":
|
| 24 |
+
return math.tan(num1)
|
| 25 |
+
elif operation == "sqrt":
|
| 26 |
+
return math.sqrt(num1)
|
| 27 |
+
elif operation == "sinh":
|
| 28 |
+
return math.sinh(num1)
|
| 29 |
+
elif operation == "cosh":
|
| 30 |
+
return math.cosh(num1)
|
| 31 |
+
elif operation == "tanh":
|
| 32 |
+
return math.tanh(num1)
|
| 33 |
|
| 34 |
demo = gr.Interface(
|
| 35 |
fn=calculator,
|
| 36 |
inputs=[
|
| 37 |
gr.Number(value=4),
|
| 38 |
+
gr.Radio(["add", "subtract", "multiply", "divide", "square", "cube", "exponential", "sin", "cos", "tan", "sqrt", "sinh", "cosh", "tanh"]),
|
| 39 |
+
gr.Number(value=2, label="Second Number (optional)", optional=True)
|
| 40 |
],
|
| 41 |
outputs="number",
|
| 42 |
examples=[
|
|
|
|
| 44 |
[4, "divide", 2],
|
| 45 |
[-4, "multiply", 2.5],
|
| 46 |
[0, "subtract", 1.2],
|
| 47 |
+
[2, "exponential", 3],
|
| 48 |
+
[1.5, "sin"],
|
| 49 |
+
[2.3, "cos"],
|
| 50 |
+
[0.8, "tan"],
|
| 51 |
+
[9, "sqrt"],
|
| 52 |
+
[1.2, "sinh"],
|
| 53 |
+
[2.1, "cosh"],
|
| 54 |
+
[0.7, "tanh"]
|
| 55 |
],
|
| 56 |
title="Scientific Calculator",
|
| 57 |
description="Here's a sample scientific calculator. Enjoy! Code by: Freddy Aboulton Improved by: Usually3"
|