Spaces:
Sleeping
Sleeping
File size: 943 Bytes
d0e3937 8b4eea2 0815b5a 8b4eea2 d0e3937 8b4eea2 243fa01 8b4eea2 243fa01 8b4eea2 243fa01 8b4eea2 0815b5a 8b4eea2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import gradio as gr
def calculator(input_text):
try:
return str(eval(input_text))
except:
return "Error"
def update_input(input_text, new_value):
if new_value == "C":
return ""
elif new_value == "=":
try:
return str(eval(input_text))
except:
return "Error"
else:
return input_text + new_value
with gr.Blocks() as iface:
gr.Markdown("# Simple Calculator")
with gr.Row():
input_display = gr.Textbox(value="", label="Display")
button_layout = [
["7", "8", "9", "/"],
["4", "5", "6", "*"],
["1", "2", "3", "-"],
["0", ".", "C", "+"],
["="]
]
for row in button_layout:
with gr.Row():
for button in row:
btn = gr.Button(button)
btn.click(update_input, inputs=[input_display, btn], outputs=input_display)
iface.launch() |