Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|