Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ history = []
|
|
| 6 |
|
| 7 |
def calculate(expression):
|
| 8 |
try:
|
| 9 |
-
# Input validation
|
| 10 |
if not re.match(r'^[\d\s\+\-\*/\(\)\^\.\w]+$', expression):
|
| 11 |
raise ValueError("Invalid characters in expression")
|
| 12 |
|
|
@@ -28,7 +27,6 @@ def calculate(expression):
|
|
| 28 |
def update_expression(expression, value):
|
| 29 |
if expression == "0" and value not in ['.', '(', ')']:
|
| 30 |
return value
|
| 31 |
-
# Automatically add brackets for functions
|
| 32 |
if value in ['sin', 'cos', 'tan', 'log', 'ln', 'sqrt']:
|
| 33 |
return expression + value + '('
|
| 34 |
return expression + value
|
|
@@ -59,7 +57,7 @@ with gr.Blocks(css=css) as iface:
|
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column(scale=3):
|
| 62 |
-
with gr.
|
| 63 |
# Number pad
|
| 64 |
for i in range(3):
|
| 65 |
with gr.Row():
|
|
@@ -72,7 +70,7 @@ with gr.Blocks(css=css) as iface:
|
|
| 72 |
btn_equals = gr.Button("=", elem_classes=["calculator-button", "basic-op-button"])
|
| 73 |
|
| 74 |
with gr.Column(scale=2):
|
| 75 |
-
with gr.
|
| 76 |
# Basic operations
|
| 77 |
for op, symbol in [("add", "+"), ("sub", "-"), ("mul", "*"), ("div", "/")]:
|
| 78 |
globals()[f"btn_{op}"] = gr.Button(symbol, elem_classes=["calculator-button", "basic-op-button"])
|
|
@@ -82,7 +80,7 @@ with gr.Blocks(css=css) as iface:
|
|
| 82 |
btn_backspace = gr.Button("⌫", elem_classes=["calculator-button", "basic-op-button"])
|
| 83 |
|
| 84 |
with gr.Column(scale=2):
|
| 85 |
-
with gr.
|
| 86 |
# Advanced operations
|
| 87 |
for func in ["sin", "cos", "tan", "log", "ln", "sqrt"]:
|
| 88 |
globals()[f"btn_{func}"] = gr.Button(func, elem_classes=["calculator-button", "advanced-op-button"])
|
|
|
|
| 6 |
|
| 7 |
def calculate(expression):
|
| 8 |
try:
|
|
|
|
| 9 |
if not re.match(r'^[\d\s\+\-\*/\(\)\^\.\w]+$', expression):
|
| 10 |
raise ValueError("Invalid characters in expression")
|
| 11 |
|
|
|
|
| 27 |
def update_expression(expression, value):
|
| 28 |
if expression == "0" and value not in ['.', '(', ')']:
|
| 29 |
return value
|
|
|
|
| 30 |
if value in ['sin', 'cos', 'tan', 'log', 'ln', 'sqrt']:
|
| 31 |
return expression + value + '('
|
| 32 |
return expression + value
|
|
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column(scale=3):
|
| 60 |
+
with gr.Column(elem_classes=["calculator-box"]):
|
| 61 |
# Number pad
|
| 62 |
for i in range(3):
|
| 63 |
with gr.Row():
|
|
|
|
| 70 |
btn_equals = gr.Button("=", elem_classes=["calculator-button", "basic-op-button"])
|
| 71 |
|
| 72 |
with gr.Column(scale=2):
|
| 73 |
+
with gr.Column(elem_classes=["calculator-box"]):
|
| 74 |
# Basic operations
|
| 75 |
for op, symbol in [("add", "+"), ("sub", "-"), ("mul", "*"), ("div", "/")]:
|
| 76 |
globals()[f"btn_{op}"] = gr.Button(symbol, elem_classes=["calculator-button", "basic-op-button"])
|
|
|
|
| 80 |
btn_backspace = gr.Button("⌫", elem_classes=["calculator-button", "basic-op-button"])
|
| 81 |
|
| 82 |
with gr.Column(scale=2):
|
| 83 |
+
with gr.Column(elem_classes=["calculator-box"]):
|
| 84 |
# Advanced operations
|
| 85 |
for func in ["sin", "cos", "tan", "log", "ln", "sqrt"]:
|
| 86 |
globals()[f"btn_{func}"] = gr.Button(func, elem_classes=["calculator-button", "advanced-op-button"])
|