Spaces:
No application file
No application file
File size: 1,108 Bytes
dad3afe |
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 |
import gradio as gr
# Function to perform the calculator operations
def calculate_expression(expression):
try:
# Using eval to evaluate the mathematical expression
result = eval(expression)
return result
except:
return "Error"
# Create the interface using Gradio
def create_calculator():
with gr.Blocks() as demo:
gr.Markdown("### Simple Calculator")
# Create the input box where users can enter expressions
expression_input = gr.Textbox(label="Enter Expression", placeholder="e.g., 3 + 4", lines=1)
# Output area to show the result
result_output = gr.Textbox(label="Result", interactive=False)
# Button to trigger calculation
calculate_button = gr.Button("Calculate")
# Link the button to the calculation function
calculate_button.click(fn=calculate_expression, inputs=expression_input, outputs=result_output)
return demo
# Run the Gradio app
if __name__ == "__main__":
calculator_app = create_calculator()
calculator_app.launch()
|