Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,6 @@
|
|
1 |
-
import
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
st.title("🧮 Simple Calculator")
|
6 |
-
|
7 |
-
# Input numbers
|
8 |
-
num1 = st.number_input("Enter first number:", format="%f")
|
9 |
-
num2 = st.number_input("Enter second number:", format="%f")
|
10 |
-
|
11 |
-
# Choose operation
|
12 |
-
operation = st.selectbox(
|
13 |
-
"Select Operation:",
|
14 |
-
("Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)",
|
15 |
-
"Modulus (%)", "Power (^)", "Floor Division (//)")
|
16 |
-
)
|
17 |
-
|
18 |
-
# Perform calculation on button click
|
19 |
-
if st.button("Calculate"):
|
20 |
try:
|
21 |
if operation == "Addition (+)":
|
22 |
result = num1 + num2
|
@@ -32,6 +16,25 @@ if st.button("Calculate"):
|
|
32 |
result = num1 ** num2
|
33 |
elif operation == "Floor Division (//)":
|
34 |
result = num1 // num2
|
35 |
-
|
|
|
|
|
36 |
except Exception as e:
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
|
3 |
+
def calculate(num1, operation, num2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
try:
|
5 |
if operation == "Addition (+)":
|
6 |
result = num1 + num2
|
|
|
16 |
result = num1 ** num2
|
17 |
elif operation == "Floor Division (//)":
|
18 |
result = num1 // num2
|
19 |
+
else:
|
20 |
+
return "Invalid operation selected."
|
21 |
+
return f"Result: {result}"
|
22 |
except Exception as e:
|
23 |
+
return f"Error: {e}"
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("## 🧮 Simple Calculator")
|
27 |
+
with gr.Row():
|
28 |
+
num1 = gr.Number(label="First Number")
|
29 |
+
operation = gr.Dropdown(
|
30 |
+
["Addition (+)", "Subtraction (-)", "Multiplication (×)", "Division (÷)",
|
31 |
+
"Modulus (%)", "Power (^)", "Floor Division (//)"],
|
32 |
+
label="Operation"
|
33 |
+
)
|
34 |
+
num2 = gr.Number(label="Second Number")
|
35 |
+
calculate_button = gr.Button("Calculate")
|
36 |
+
result_output = gr.Textbox(label="Result")
|
37 |
+
|
38 |
+
calculate_button.click(fn=calculate, inputs=[num1, operation, num2], outputs=result_output)
|
39 |
+
|
40 |
+
demo.launch()
|