Spaces:
Sleeping
Sleeping
Download app.py from nightprogrammer/coder_hangout: direct link, hf CLI and curl.
- Browser
- Download file 5.87 kB
-
https://huggingface.co/spaces/nightprogrammer/coder_hangout/resolve/main/app.py
- Command line
-
hf download hf://spaces/nightprogrammer/coder_hangout/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nightprogrammer/coder_hangout/resolve/main/app.py
5.87 kB
| import streamlit as st | |
| import math | |
| import time | |
| # Inject custom CSS for the theme and hover effect | |
| st.markdown( | |
| """ | |
| <style> | |
| body { | |
| background: linear-gradient(to right, #5e03fc, #2575fc); /* Purple-blue gradient */ | |
| color: white; | |
| } | |
| div[data-testid="stSidebar"] { | |
| background: #5e03fc; /* Sidebar background */ | |
| } | |
| div[data-testid="stMarkdownContainer"] h1, div[data-testid="stMarkdownContainer"] h2, | |
| div[data-testid="stMarkdownContainer"] h3 { | |
| color: #ffffff; /* Title color */ | |
| } | |
| button { | |
| background-color: #5e03fc !important; /* Button background */ | |
| color: white !important; /* Button text color */ | |
| border-radius: 5px !important; | |
| } | |
| button:hover { | |
| background-color: #5e03fc !important; /* Hover color */ | |
| color: #e0e0ff !important; /* Slightly lighter hover text for effect */ | |
| } | |
| div[data-testid="stMarkdownContainer"] p { | |
| font-family: 'Trebuchet MS', sans-serif; /* Text style */ | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| # Title with updated theme | |
| st.title("๐ Advanced Night Calculator") | |
| # Animation for menu reveal | |
| with st.expander("๐๏ธ Open the Menu (Click Me!)"): | |
| st.markdown( | |
| """ | |
| <style> | |
| @keyframes fadeIn { | |
| from {opacity: 0;} | |
| to {opacity: 1;} | |
| } | |
| div[data-testid="stMarkdownContainer"] { | |
| animation: fadeIn 1s ease-in-out; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| # Menu options with animated reveal | |
| operation = st.selectbox( | |
| "Choose an operation:", | |
| [ | |
| "โ Addition", "โ Subtraction", "โ๏ธ Multiplication", "โ Division", | |
| "๐ข Exponentiation", "๐ Square Root", "๐ Logarithm", "๐ก Factorial", | |
| "๐ Trigonometry (sin, cos, tan)", "๐งฎ Percentage", "โ Modulus", "๐ Inverse (1/x)", "โก Absolute Value" | |
| ] | |
| ) | |
| # Animation function for smooth transitions | |
| def show_animation(): | |
| placeholder = st.empty() | |
| with placeholder: | |
| st.info("โจ Loading your selection...") | |
| time.sleep(1.5) # Simulate a processing time | |
| placeholder.empty() | |
| # Logic for operations with input fields | |
| if operation in ["โ Addition", "โ Subtraction", "โ๏ธ Multiplication", "โ Division", "๐ข Exponentiation"]: | |
| num1 = st.number_input("Enter the first number:", value=0.0) | |
| num2 = st.number_input("Enter the second number:", value=0.0) | |
| if st.button("๐ Calculate"): | |
| show_animation() | |
| if operation == "โ Addition": | |
| st.success(f"Result: {num1 + num2}") | |
| elif operation == "โ Subtraction": | |
| st.success(f"Result: {num1 - num2}") | |
| elif operation == "โ๏ธ Multiplication": | |
| st.success(f"Result: {num1 * num2}") | |
| elif operation == "โ Division": | |
| if num2 != 0: | |
| st.success(f"Result: {num1 / num2}") | |
| else: | |
| st.error("๐ซ Error: Division by zero is not allowed!") | |
| elif operation == "๐ข Exponentiation": | |
| st.success(f"Result: {math.pow(num1, num2)}") | |
| elif operation == "๐ Square Root": | |
| num = st.number_input("Enter the number:", value=0.0) | |
| if st.button("๐ Calculate"): | |
| show_animation() | |
| if num >= 0: | |
| st.success(f"Result: {math.sqrt(num)}") | |
| else: | |
| st.error("๐ซ Error: Cannot calculate the square root of a negative number!") | |
| elif operation == "๐ Logarithm": | |
| num = st.number_input("Enter the number (greater than 0):", value=1.0) | |
| if st.button("๐ Calculate"): | |
| show_animation() | |
| if num > 0: | |
| st.success(f"Result: {math.log(num)}") | |
| else: | |
| st.error("๐ซ Error: Logarithm undefined for non-positive numbers!") | |
| elif operation == "๐ก Factorial": | |
| num = st.number_input("Enter a non-negative integer:", value=0, step=1, min_value=0, format="%d") | |
| if st.button("๐ Calculate"): | |
| show_animation() | |
| st.success(f"Result: {math.factorial(num)}") | |
| elif operation == "๐ Trigonometry (sin, cos, tan)": | |
| angle = st.number_input("Enter the angle in degrees:", value=0.0) | |
| if st.button("๐ Calculate"): | |
| show_animation() | |
| radians = math.radians(angle) | |
| st.write(f"Sin({angle}ยฐ): {math.sin(radians):.4f}") | |
| st.write(f"Cos({angle}ยฐ): {math.cos(radians):.4f}") | |
| st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}") | |
| elif operation == "๐งฎ Percentage": | |
| total = st.number_input("Enter the total value:", value=1.0) | |
| portion = st.number_input("Enter the portion value:", value=0.0) | |
| if st.button("๐ Calculate Percentage"): | |
| show_animation() | |
| if total != 0: | |
| result = (portion / total) * 100 | |
| st.success(f"Result: {result}%") | |
| else: | |
| st.error("๐ซ Error: Total value cannot be zero!") | |
| elif operation == "โ Modulus": | |
| num1 = st.number_input("Enter the first number:", value=0.0) | |
| num2 = st.number_input("Enter the second number:", value=0.0) | |
| if st.button("๐ Calculate Modulus"): | |
| show_animation() | |
| if num2 != 0: | |
| st.success(f"Result: {num1 % num2}") | |
| else: | |
| st.error("๐ซ Error: Modulus undefined for division by zero!") | |
| elif operation == "๐ Inverse (1/x)": | |
| num = st.number_input("Enter the number:", value=0.0) | |
| if st.button("๐ Calculate Inverse"): | |
| show_animation() | |
| if num != 0: | |
| st.success(f"Result: {1 / num}") | |
| else: | |
| st.error("๐ซ Error: Inverse undefined for zero!") | |
| elif operation == "โก Absolute Value": | |
| num = st.number_input("Enter the number:", value=0.0) | |
| if st.button("๐ Calculate Absolute Value"): | |
| show_animation() | |
| st.success(f"Result: {abs(num)}") |