Commit
·
22e812d
1
Parent(s):
abf54dd
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def calculator(num1, operation, num2):
|
| 4 |
+
if operation == "add":
|
| 5 |
+
return num1 + num2
|
| 6 |
+
elif operation == "subtract":
|
| 7 |
+
return num1 - num2
|
| 8 |
+
elif operation == "multiply":
|
| 9 |
+
return num1 * num2
|
| 10 |
+
elif operation == "divide":
|
| 11 |
+
return num1 / num2
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=calculator,
|
| 16 |
+
inputs=[
|
| 17 |
+
gr.Number(value=4),
|
| 18 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
| 19 |
+
"number"
|
| 20 |
+
],
|
| 21 |
+
outputs="number",
|
| 22 |
+
examples=[
|
| 23 |
+
[5, "add", 3],
|
| 24 |
+
[4, "divide", 2],
|
| 25 |
+
[-4, "multiply", 2.5],
|
| 26 |
+
[0, "subtract", 1.2],
|
| 27 |
+
],
|
| 28 |
+
title="test calculator",
|
| 29 |
+
description="heres a sample **toy calculator**. enjoy!",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|