Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import math | |
| st.set_page_config(page_title="🧮 Advanced Calculator", layout="centered") | |
| st.title("🧠 Advanced Calculator") | |
| st.markdown("Perform advanced mathematical calculations securely and interactively.") | |
| expression = st.text_input("Enter your expression (e.g., sin(30) + log(10) + 2^3):") | |
| # Safe math function map | |
| allowed_names = { | |
| k: v for k, v in math.__dict__.items() if not k.startswith("__") | |
| } | |
| allowed_names.update({ | |
| 'np': np, | |
| 'sqrt': np.sqrt, | |
| 'pow': pow, | |
| 'abs': abs | |
| }) | |
| def evaluate_expression(expr): | |
| try: | |
| # Replace ^ with ** for Python syntax | |
| expr = expr.replace("^", "**") | |
| result = eval(expr, {"__builtins__": {}}, allowed_names) | |
| return result | |
| except Exception as e: | |
| return f"❌ Error: {e}" | |
| if expression: | |
| result = evaluate_expression(expression) | |
| st.subheader("🧾 Result:") | |
| st.code(result, language='text') | |
| st.markdown("---") | |
| st.caption("Built using Streamlit | © 2025 AdvancedCalc") | |