Spaces:
Sleeping
Sleeping
Create app.py (#1)
Browse files- Create app.py (bc7746cdfb67b8cde8a2881f143a5f1486e2d044)
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
def calculator(num1, operation, num2):
|
| 6 |
+
if operation == "add":
|
| 7 |
+
return num1 + num2
|
| 8 |
+
elif operation == "subtract":
|
| 9 |
+
return num1 - num2
|
| 10 |
+
elif operation == "multiply":
|
| 11 |
+
return num1 * num2
|
| 12 |
+
elif operation == "divide":
|
| 13 |
+
if num2 == 0:
|
| 14 |
+
raise gr.Error("Cannot divide by zero!")
|
| 15 |
+
return num1 / num2
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
calculator,
|
| 19 |
+
[
|
| 20 |
+
"number",
|
| 21 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
| 22 |
+
"number"
|
| 23 |
+
],
|
| 24 |
+
"number",
|
| 25 |
+
examples=[
|
| 26 |
+
[45, "add", 3],
|
| 27 |
+
[3.14, "divide", 2],
|
| 28 |
+
[144, "multiply", 2.5],
|
| 29 |
+
[0, "subtract", 1.2],
|
| 30 |
+
],
|
| 31 |
+
title="Shaheen Calculator",
|
| 32 |
+
description="Here's a sample toy calculator.",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
demo.launch(inline = False)
|