Kvikontent commited on
Commit
10cd742
·
verified ·
1 Parent(s): 950aaff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def money_calculator(amount, operation, operand):
4
+ if operation == 'add':
5
+ result = amount + operand
6
+ elif operation == 'subtract':
7
+ result = amount - operand
8
+ elif operation == 'multiply':
9
+ result = amount * operand
10
+ elif operation == 'divide':
11
+ result = amount / operand if operand != 0 else "Cannot divide by zero."
12
+ else:
13
+ result = 'Invalid operation'
14
+
15
+ return result
16
+
17
+ def exponentiation_calculator(base, desired_result):
18
+ try:
19
+ # The exponentiation is solved as finding the nth root of the desired_result
20
+ exponent = round(desired_result ** (1/base), 4)
21
+ return f"{base}^{exponent} = {desired_result}"
22
+ except Exception as e:
23
+ return str(e)
24
+
25
+ with gr.Blocks() as app:
26
+ with gr.Tab("Money Calculator"):
27
+ with gr.Box():
28
+ with gr.Row():
29
+ amount = gr.Number(label="Amount")
30
+ operation = gr.Dropdown(choices=['add', 'subtract', 'multiply', 'divide'], label="Operation")
31
+ operand = gr.Number(label="Operand")
32
+ money_result = gr.Number(label="Result", interactive=False)
33
+
34
+ money_calculate_btn = gr.Button("Calculate")
35
+ money_calculate_btn.click(money_calculator, inputs=[amount, operation, operand], outputs=[money_result])
36
+
37
+ with gr.Tab("Exponentiation Calculator"):
38
+ with gr.Box():
39
+ with gr.Row():
40
+ base = gr.Number(label="Base (n) [To find n^x]")
41
+ desired_result = gr.Number(label="Desired Result (To get from n^x)")
42
+ exp_result = gr.Textbox(label="Expression Result", interactive=False)
43
+
44
+ exponentiation_btn = gr.Button("Calculate")
45
+ exponentiation_btn.click(exponentiation_calculator, inputs=[base, desired_result], outputs=[exp_result])
46
+
47
+ app.launch()