Kvikontent commited on
Commit
75753aa
·
verified ·
1 Parent(s): 10cd742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -25
app.py CHANGED
@@ -1,14 +1,17 @@
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
 
@@ -16,32 +19,28 @@ def money_calculator(amount, operation, operand):
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()
 
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
+ try:
12
+ result = amount / operand
13
+ except ZeroDivisionError:
14
+ result = "Cannot divide by zero."
15
  else:
16
  result = 'Invalid operation'
17
 
 
19
 
20
  def exponentiation_calculator(base, desired_result):
21
  try:
22
+ # The exponentiation is solved as finding the n-th root of the desired_result
23
+ exponent = round(desired_result ** (1 / float(base)), 4)
24
  return f"{base}^{exponent} = {desired_result}"
25
  except Exception as e:
26
  return str(e)
27
 
28
  with gr.Blocks() as app:
29
  with gr.Tab("Money Calculator"):
30
+ with gr.Row():
31
+ amount = gr.Number(label="Amount")
32
+ operation = gr.Dropdown(choices=['Add', 'Subtract', 'Multiply', 'Divide'], label="Operation")
33
+ operand = gr.Number(label="Operand")
34
+ money_result = gr.Number(label="Result", interactive=False)
35
+ money_calculate_btn = gr.Button("Calculate")
36
+ money_calculate_btn.click(money_calculator, inputs=[amount, operation, operand], outputs=[money_result])
 
 
37
 
38
  with gr.Tab("Exponentiation Calculator"):
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
+ exponentiation_btn = gr.Button("Calculate")
44
+ exponentiation_btn.click(exponentiation_calculator, inputs=[base, desired_result], outputs=[exp_result])
 
 
45
 
46
+ app.launch()