Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,45 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import math
|
| 3 |
import time
|
| 4 |
|
| 5 |
# Title with Emoji
|
| 6 |
-
st.title("
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
st.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def show_animation():
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
st.
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
if operation == "β Addition":
|
| 32 |
-
st.success(f"Result: {num1 + num2}")
|
| 33 |
-
elif operation == "β Subtraction":
|
| 34 |
-
st.success(f"Result: {num1 - num2}")
|
| 35 |
-
elif operation == "βοΈ Multiplication":
|
| 36 |
-
st.success(f"Result: {num1 * num2}")
|
| 37 |
-
elif operation == "β Division":
|
| 38 |
-
if num2 != 0:
|
| 39 |
-
st.success(f"Result: {num1 / num2}")
|
| 40 |
-
else:
|
| 41 |
-
st.error("π« Error: Division by zero is not allowed!")
|
| 42 |
-
elif operation == "π’ Exponentiation":
|
| 43 |
-
st.success(f"Result: {math.pow(num1, num2)}")
|
| 44 |
-
|
| 45 |
-
# Square Root Calculation
|
| 46 |
-
elif operation == "π Square Root":
|
| 47 |
-
num = st.number_input("Enter the number: π·οΈ", value=0.0)
|
| 48 |
-
if st.button("π Calculate"):
|
| 49 |
-
show_animation()
|
| 50 |
-
if num >= 0:
|
| 51 |
-
st.success(f"Result: {math.sqrt(num)}")
|
| 52 |
-
else:
|
| 53 |
-
st.error("π« Error: Cannot calculate the square root of a negative number!")
|
| 54 |
-
|
| 55 |
-
# Logarithm Calculation
|
| 56 |
-
elif operation == "π Logarithm":
|
| 57 |
-
num = st.number_input("Enter the number (greater than 0): π·οΈ", value=1.0)
|
| 58 |
-
if st.button("π Calculate"):
|
| 59 |
-
show_animation()
|
| 60 |
-
if num > 0:
|
| 61 |
-
st.success(f"Result: {math.log(num)}")
|
| 62 |
-
else:
|
| 63 |
-
st.error("π« Error: Logarithm undefined for non-positive numbers!")
|
| 64 |
-
|
| 65 |
-
# Factorial Calculation
|
| 66 |
-
elif operation == "π‘ Factorial":
|
| 67 |
-
num = st.number_input("Enter a non-negative integer: π·οΈ", value=0, step=1, min_value=0, format="%d")
|
| 68 |
-
if st.button("π Calculate"):
|
| 69 |
-
show_animation()
|
| 70 |
-
st.success(f"Result: {math.factorial(num)}")
|
| 71 |
-
|
| 72 |
-
# Trigonometry
|
| 73 |
-
elif operation == "π Trigonometry (sin, cos, tan)":
|
| 74 |
-
angle = st.number_input("Enter the angle in degrees: π·οΈ", value=0.0)
|
| 75 |
-
if st.button("π Calculate"):
|
| 76 |
-
show_animation()
|
| 77 |
-
radians = math.radians(angle)
|
| 78 |
-
st.write(f"Sin({angle}Β°): {math.sin(radians):.4f}")
|
| 79 |
-
st.write(f"Cos({angle}Β°): {math.cos(radians):.4f}")
|
| 80 |
-
st.write(f"Tan({angle}Β°): {math.tan(radians):.4f}")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
# Title with Emoji
|
| 5 |
+
st.title("π« Advanced Calculator with Menu Animation π»")
|
| 6 |
+
|
| 7 |
+
# Animation for menu reveal
|
| 8 |
+
with st.expander("ποΈ Open the Menu (Click Me!)"):
|
| 9 |
+
st.markdown(
|
| 10 |
+
"""
|
| 11 |
+
<style>
|
| 12 |
+
@keyframes fadeIn {
|
| 13 |
+
from {opacity: 0;}
|
| 14 |
+
to {opacity: 1;}
|
| 15 |
+
}
|
| 16 |
+
div[data-testid="stMarkdownContainer"] {
|
| 17 |
+
animation: fadeIn 1s ease-in-out;
|
| 18 |
+
}
|
| 19 |
+
</style>
|
| 20 |
+
""",
|
| 21 |
+
unsafe_allow_html=True,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Menu options with animated reveal
|
| 25 |
+
operation = st.selectbox(
|
| 26 |
+
"Choose an operation:",
|
| 27 |
+
[
|
| 28 |
+
"β Addition", "β Subtraction", "βοΈ Multiplication", "β Division",
|
| 29 |
+
"π’ Exponentiation", "π Square Root", "π Logarithm", "π‘ Factorial",
|
| 30 |
+
"π Trigonometry (sin, cos, tan)"
|
| 31 |
+
]
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Animation function for smooth transitions
|
| 35 |
def show_animation():
|
| 36 |
+
placeholder = st.empty()
|
| 37 |
+
with placeholder:
|
| 38 |
+
st.info("β¨ Loading your selection...")
|
| 39 |
+
time.sleep(1.5) # Simulate a processing time
|
| 40 |
+
placeholder.empty()
|
| 41 |
+
|
| 42 |
+
# Add logic for the calculator
|
| 43 |
+
if operation:
|
| 44 |
+
show_animation()
|
| 45 |
+
st.success(f"π You selected: {operation} π")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|