File size: 1,868 Bytes
10cd742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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':
        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()