0Hojoon0 commited on
Commit
0188497
·
verified ·
1 Parent(s): c7bf7e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -36
app.py CHANGED
@@ -1,38 +1,12 @@
1
  import gradio as gr
2
 
3
- # Create a Gradio interface
4
- interface = gr.Interface()
5
-
6
- # Add a text input for the user to enter their equation
7
- text_input = gr.TextInput(interface, 'Enter an equation:')
8
-
9
- # Add a button to submit the equation
10
- submit_button = gr.Button(interface, 'Submit')
11
-
12
- # Create a function to evaluate the equation
13
- def evaluate_equation(equ):
14
- # Parse the equation string into tokens
15
- tokens = equ.split('')
16
-
17
- # Define a dictionary to map operators to their corresponding functions
18
- op_dict = {'+': lambda x, y: x + y,
19
- '-': lambda x, y: x - y,
20
- '*': lambda x, y: x * y,
21
- '/': lambda x, y: x / y}
22
-
23
- # Evaluate the expression recursively
24
- def eval_expression(expr):
25
- if expr == '':
26
- return None
27
- elif expr in op_dict:
28
- return op_dict[expr](eval_expression(tokens[:-1]), eval_expression(tokens[-1]))
29
- else:
30
- return float(expr)
31
-
32
- return eval_expression(tokens)
33
-
34
- # Add a callback function to the button to evaluate the equation when clicked
35
- submit_button.on_click(lambda: interface.update_output(evaluate_equation(text_input.value)))
36
-
37
- # Run the Gradio interface
38
- interface.run()
 
1
  import gradio as gr
2
 
3
+ def add_numbers(num1, num2):
4
+ return num1 + num2
5
+
6
+ gr.Interface(
7
+ fn=add_numbers,
8
+ inputs=["number", "number"],
9
+ outputs="number",
10
+ title="Simple Calculator",
11
+ description="Add two numbers."
12
+ ).launch()