Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import datetime, date | |
| # Page setup | |
| st.set_page_config(page_title="AGE Calculator", page_icon="๐", layout="centered") | |
| # Custom CSS for enhanced visuals | |
| st.markdown(""" | |
| <style> | |
| .title { | |
| text-align: center; | |
| font-size: 60px; | |
| color: #ff4c4c; | |
| font-weight: bold; | |
| margin-bottom: 30px; | |
| } | |
| .subtitle { | |
| text-align: center; | |
| font-size: 20px; | |
| color: #555; | |
| margin-bottom: 20px; | |
| } | |
| .result-box { | |
| background-color: #f0f2f6; | |
| padding: 30px; | |
| border-radius: 20px; | |
| text-align: center; | |
| box-shadow: 2px 2px 10px rgba(0,0,0,0.1); | |
| margin-top: 30px; | |
| } | |
| .years { | |
| color: #FF5733; | |
| font-size: 36px; | |
| font-weight: bold; | |
| } | |
| .months { | |
| color: #33C3FF; | |
| font-size: 32px; | |
| font-weight: bold; | |
| } | |
| .days { | |
| color: #8D33FF; | |
| font-size: 28px; | |
| font-weight: bold; | |
| } | |
| .emoji { | |
| font-size: 48px; | |
| } | |
| .simple { | |
| margin-top: 15px; | |
| font-size: 20px; | |
| color: #444; | |
| font-style: italic; | |
| } | |
| .stButton>button { | |
| background-color: #ff4c4c; | |
| color: white; | |
| border-radius: 10px; | |
| padding: 10px 24px; | |
| font-size: 18px; | |
| font-weight: bold; | |
| margin-top: 10px; | |
| margin-right: 10px; | |
| } | |
| .stButton>button:hover { | |
| background-color: #e84343; | |
| transition: 0.3s ease-in-out; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Title & Subtitle | |
| st.markdown('<div class="title">๐ AGE Calculator ๐</div>', unsafe_allow_html=True) | |
| st.markdown('<div class="subtitle">Select your date of birth and let the magic begin โจ</div>', unsafe_allow_html=True) | |
| # Session state for DOB and result control | |
| if "dob" not in st.session_state: | |
| st.session_state.dob = date(1990, 1, 1) | |
| if "show_result" not in st.session_state: | |
| st.session_state.show_result = False | |
| # Input: Date of birth | |
| dob = st.date_input( | |
| "๐ Select your Date of Birth", | |
| min_value=date(1900, 1, 1), | |
| max_value=date.today(), | |
| value=st.session_state.dob | |
| ) | |
| # Buttons in columns | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| if st.button("โจ Calculate My Age"): | |
| st.session_state.dob = dob | |
| st.session_state.show_result = True | |
| with col2: | |
| if st.button("๐ Clear"): | |
| st.session_state.dob = date(1990, 1, 1) | |
| st.session_state.show_result = False | |
| st.experimental_rerun() | |
| # Display Result | |
| if st.session_state.show_result: | |
| today = date.today() | |
| if dob > today: | |
| st.error("๐ซ Date of Birth cannot be in the future!") | |
| else: | |
| delta = today - dob | |
| years = delta.days // 365 | |
| months = (delta.days % 365) // 30 | |
| days = (delta.days % 365) % 30 | |
| st.markdown(f""" | |
| <div class="result-box"> | |
| <div class="emoji">๐ ๐งฎ๐</div> | |
| <div class="years">{years} Years</div> | |
| <div class="months">{months} Months</div> | |
| <div class="days">{days} Days</div> | |
| <div class="simple">You are {years} years, {months} months, and {days} days old.</div> | |
| </div> | |
| """, unsafe_allow_html=True) | |