Spaces:
Sleeping
Sleeping
File size: 1,818 Bytes
10cd742 75753aa 10cd742 75753aa 10cd742 75753aa 10cd742 75753aa 10cd742 75753aa 10cd742 75753aa 10cd742 75753aa 10cd742 75753aa |
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 41 42 43 44 45 46 47 |
import gradio as gr
def money_calculator(amount, operation, operand):
if operation == 'Add':
result = amount + operand
elif operation == 'Subtract':
result = amount - operand
elif operation == 'Multiply':
result = amount * operand
elif operation == 'Divide':
try:
result = amount / operand
except ZeroDivisionError:
result = "Cannot divide by zero."
else:
result = 'Invalid operation'
return result
def exponentiation_calculator(base, desired_result):
try:
# The exponentiation is solved as finding the n-th root of the desired_result
exponent = round(desired_result ** (1 / float(base)), 4)
return f"{base}^{exponent} = {desired_result}"
except Exception as e:
return str(e)
with gr.Blocks() as app:
with gr.Tab("Money Calculator"):
with gr.Row():
amount = gr.Number(label="Amount")
operation = gr.Dropdown(choices=['Add', 'Subtract', 'Multiply', 'Divide'], label="Operation")
operand = gr.Number(label="Operand")
money_result = gr.Number(label="Result", interactive=False)
money_calculate_btn = gr.Button("Calculate")
money_calculate_btn.click(money_calculator, inputs=[amount, operation, operand], outputs=[money_result])
with gr.Tab("Exponentiation Calculator"):
with gr.Row():
base = gr.Number(label="Base (n) [To find n^x]")
desired_result = gr.Number(label="Desired Result (To get from n^x)")
exp_result = gr.Textbox(label="Expression Result", interactive=False)
exponentiation_btn = gr.Button("Calculate")
exponentiation_btn.click(exponentiation_calculator, inputs=[base, desired_result], outputs=[exp_result])
app.launch()
|