Spaces:
Sleeping
Sleeping
Add app.py via Space Creator
Browse files
app.py
CHANGED
|
@@ -1,82 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
# def calculator():
|
| 19 |
-
# print("Simple Calculator")
|
| 20 |
-
# print("Operations: + - * /")
|
| 21 |
-
#
|
| 22 |
-
# while True:
|
| 23 |
-
# op = input("Enter operation (+, -, *, /) or 'q' to quit: ")
|
| 24 |
-
#
|
| 25 |
-
# if op.lower() == 'q':
|
| 26 |
-
# print("Exiting calculator.")
|
| 27 |
-
# break
|
| 28 |
-
#
|
| 29 |
-
# if op not in ['+', '-', '*', '/']:
|
| 30 |
-
# print("Invalid operation.")
|
| 31 |
-
# continue
|
| 32 |
-
#
|
| 33 |
-
# try:
|
| 34 |
-
# num1 = float(input("Enter first number: "))
|
| 35 |
-
# num2 = float(input("Enter second number: "))
|
| 36 |
-
# except ValueError:
|
| 37 |
-
# print("Invalid input. Please enter numbers.")
|
| 38 |
-
# continue
|
| 39 |
-
#
|
| 40 |
-
# if op == '+':
|
| 41 |
-
# result = add(num1, num2)
|
| 42 |
-
# elif op == '-':
|
| 43 |
-
# result = subtract(num1, num2)
|
| 44 |
-
# elif op == '*':
|
| 45 |
-
# result = multiply(num1, nu
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
with gr.Row():
|
| 60 |
-
with gr.Column():
|
| 61 |
-
input_box = gr.Textbox(
|
| 62 |
-
label="Input Text",
|
| 63 |
-
placeholder="Enter text to process...",
|
| 64 |
-
lines=3
|
| 65 |
-
)
|
| 66 |
-
submit_btn = gr.Button("Process", variant="primary")
|
| 67 |
-
|
| 68 |
-
with gr.Row():
|
| 69 |
-
output_box = gr.Textbox(
|
| 70 |
-
label="Output",
|
| 71 |
-
interactive=False,
|
| 72 |
-
lines=5
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
submit_btn.click(
|
| 76 |
-
fn=process_input,
|
| 77 |
-
inputs=[input_box],
|
| 78 |
-
outputs=[output_box]
|
| 79 |
-
)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def calculator(num1, op, num2):
|
| 4 |
+
if op == "+":
|
| 5 |
+
result = num1 + num2
|
| 6 |
+
elif op == "-":
|
| 7 |
+
result = num1 - num2
|
| 8 |
+
elif op == "*":
|
| 9 |
+
result = num1 * num2
|
| 10 |
+
elif op == "/":
|
| 11 |
+
if num2 == 0:
|
| 12 |
+
return "Error: Division by zero"
|
| 13 |
+
result = num1 / num2
|
| 14 |
+
else:
|
| 15 |
+
return "Invalid operator"
|
| 16 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
calculator,
|
| 20 |
+
[
|
| 21 |
+
gr.Number(label="First Number"),
|
| 22 |
+
gr.Dropdown(label="Operator", choices=["+", "-", "*", "/"]),
|
| 23 |
+
gr.Number(label="Second Number")
|
| 24 |
+
],
|
| 25 |
+
gr.Textbox(label="Result"),
|
| 26 |
+
title="Simple Calculator",
|
| 27 |
+
description="A simple calculator that performs basic arithmetic operations."
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|