Kvikontent's picture
Create app.py
10cd742 verified
raw
history blame
1.87 kB
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':
result = amount / operand if operand != 0 else "Cannot divide by zero."
else:
result = 'Invalid operation'
return result
def exponentiation_calculator(base, desired_result):
try:
# The exponentiation is solved as finding the nth root of the desired_result
exponent = round(desired_result ** (1/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.Box():
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.Box():
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()