Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def calculator(num1, num2, operation):
|
4 |
+
if operation == '+':
|
5 |
+
return num1 + num2
|
6 |
+
elif operation == '-':
|
7 |
+
return num1 - num2
|
8 |
+
elif operation == '*':
|
9 |
+
return num1 * num2
|
10 |
+
elif operation == '/':
|
11 |
+
if num2 == 0:
|
12 |
+
return "除數不能為零"
|
13 |
+
return num1 / num2
|
14 |
+
else:
|
15 |
+
return "無效運算符號"
|
16 |
+
|
17 |
+
demo = gr.Interface(
|
18 |
+
fn=calculator,
|
19 |
+
inputs=[
|
20 |
+
gr.Number(label="數字1"),
|
21 |
+
gr.Number(label="數字2"),
|
22 |
+
gr.Dropdown(["+", "-", "*", "/"], label="運算符號")
|
23 |
+
],
|
24 |
+
outputs=gr.Textbox(label="結果"),
|
25 |
+
title="簡易計算機",
|
26 |
+
description="輸入兩個數字和運算符號,計算結果",
|
27 |
+
allow_flagging='never',
|
28 |
+
examples=[
|
29 |
+
[45, 3, "-"],
|
30 |
+
[3.14, 2, "/"],
|
31 |
+
[144, 2.5, "*"],
|
32 |
+
[1, 1.2, "+"],
|
33 |
+
],
|
34 |
+
)
|
35 |
+
|
36 |
+
demo.launch()
|