Spaces:
Sleeping
Sleeping
File size: 3,512 Bytes
49972bd e56bf98 49972bd e56bf98 49972bd e56bf98 49972bd e56bf98 49972bd e56bf98 49972bd e56bf98 8f23913 18cde11 8f23913 67a46b4 8f23913 18cde11 67a46b4 8f23913 67a46b4 8f23913 18cde11 67a46b4 8f23913 67a46b4 8f23913 18cde11 8f23913 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | 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)
|