Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,89 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import datetime
|
| 3 |
|
| 4 |
-
#
|
| 5 |
st.markdown("""
|
| 6 |
<style>
|
| 7 |
body {
|
| 8 |
-
|
| 9 |
-
padding: 0;
|
| 10 |
-
background-color: #f0f0f0;
|
| 11 |
font-family: 'Arial', sans-serif;
|
| 12 |
-
height: 100vh;
|
| 13 |
display: flex;
|
| 14 |
justify-content: center;
|
| 15 |
align-items: center;
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
.card {
|
| 19 |
-
background-color:
|
| 20 |
-
border-radius:
|
| 21 |
-
padding:
|
| 22 |
-
width: 350px;
|
| 23 |
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
|
|
|
| 24 |
text-align: center;
|
| 25 |
-
transition: all 0.3s ease;
|
| 26 |
}
|
| 27 |
|
| 28 |
-
.card
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
-
button {
|
| 34 |
background-color: #2575fc;
|
| 35 |
color: white;
|
| 36 |
border: none;
|
| 37 |
-
padding:
|
| 38 |
-
border-radius:
|
| 39 |
-
font-size:
|
| 40 |
cursor: pointer;
|
| 41 |
-
|
| 42 |
}
|
| 43 |
|
| 44 |
-
button:hover {
|
| 45 |
background-color: #6a11cb;
|
| 46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</style>
|
| 48 |
""", unsafe_allow_html=True)
|
| 49 |
|
| 50 |
def main():
|
|
|
|
| 51 |
st.title("Age Calculation App")
|
|
|
|
| 52 |
|
| 53 |
-
# Create input fields
|
| 54 |
-
dob = st.date_input("Date of Birth", min_value=datetime.date(1900, 1, 1), max_value=datetime.date.today())
|
| 55 |
-
current_date = st.date_input("Current Date")
|
| 56 |
|
| 57 |
-
# Simple
|
| 58 |
with st.container():
|
| 59 |
st.markdown("""
|
| 60 |
<div class="card">
|
| 61 |
-
<h3>Age
|
| 62 |
-
<p>Enter your Date of Birth and
|
| 63 |
</div>
|
| 64 |
""", unsafe_allow_html=True)
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
if st.button("Calculate Age"):
|
| 68 |
# Calculate years
|
| 69 |
years = current_date.year - dob.year
|
| 70 |
if (current_date.month, current_date.day) < (dob.month, dob.day):
|
|
@@ -86,7 +105,7 @@ def main():
|
|
| 86 |
last_day_of_prev_month = (current_date.replace(day=1) - datetime.timedelta(days=1)).day
|
| 87 |
days = last_day_of_prev_month - dob.day + current_date.day
|
| 88 |
|
| 89 |
-
# Display age
|
| 90 |
st.write(f"Your date of birth is {dob.strftime('%Y-%m-%d')} and today's date is {current_date.strftime('%Y-%m-%d')}.")
|
| 91 |
st.write(f"Your age is {years} years, {months} months, and {days} days.")
|
| 92 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import datetime
|
| 3 |
|
| 4 |
+
# Custom Styling
|
| 5 |
st.markdown("""
|
| 6 |
<style>
|
| 7 |
body {
|
| 8 |
+
background-color: #f1f5f8;
|
|
|
|
|
|
|
| 9 |
font-family: 'Arial', sans-serif;
|
|
|
|
| 10 |
display: flex;
|
| 11 |
justify-content: center;
|
| 12 |
align-items: center;
|
| 13 |
+
height: 100vh;
|
| 14 |
+
margin: 0;
|
| 15 |
}
|
| 16 |
|
| 17 |
.card {
|
| 18 |
+
background-color: #ffffff;
|
| 19 |
+
border-radius: 15px;
|
| 20 |
+
padding: 40px;
|
|
|
|
| 21 |
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 22 |
+
width: 400px;
|
| 23 |
text-align: center;
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
+
.card h3 {
|
| 27 |
+
font-size: 24px;
|
| 28 |
+
color: #2575fc;
|
| 29 |
+
margin-bottom: 20px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.card p {
|
| 33 |
+
font-size: 16px;
|
| 34 |
+
color: #333;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
.card button {
|
| 38 |
background-color: #2575fc;
|
| 39 |
color: white;
|
| 40 |
border: none;
|
| 41 |
+
padding: 15px 30px;
|
| 42 |
+
border-radius: 8px;
|
| 43 |
+
font-size: 18px;
|
| 44 |
cursor: pointer;
|
| 45 |
+
transition: background-color 0.3s;
|
| 46 |
}
|
| 47 |
|
| 48 |
+
.card button:hover {
|
| 49 |
background-color: #6a11cb;
|
| 50 |
}
|
| 51 |
+
|
| 52 |
+
.stButton>button {
|
| 53 |
+
font-size: 18px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.stDateInput>div {
|
| 57 |
+
margin-bottom: 20px;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.stTextInput>div {
|
| 61 |
+
margin-bottom: 20px;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
</style>
|
| 65 |
""", unsafe_allow_html=True)
|
| 66 |
|
| 67 |
def main():
|
| 68 |
+
# Title and App Description
|
| 69 |
st.title("Age Calculation App")
|
| 70 |
+
st.markdown("<h2 style='color:#2575fc;'>Calculate Your Age</h2>", unsafe_allow_html=True)
|
| 71 |
|
| 72 |
+
# Create input fields with icons
|
| 73 |
+
dob = st.date_input("๐
Select Date of Birth", min_value=datetime.date(1900, 1, 1), max_value=datetime.date.today())
|
| 74 |
+
current_date = st.date_input("๐ Select Current Date", max_value=datetime.date.today())
|
| 75 |
|
| 76 |
+
# Simple Card UI
|
| 77 |
with st.container():
|
| 78 |
st.markdown("""
|
| 79 |
<div class="card">
|
| 80 |
+
<h3>Age Calculator</h3>
|
| 81 |
+
<p>Enter your Date of Birth and the current date to calculate your age in years, months, and days.</p>
|
| 82 |
</div>
|
| 83 |
""", unsafe_allow_html=True)
|
| 84 |
|
| 85 |
+
# Calculate and display age on button click
|
| 86 |
+
if st.button("๐ Calculate Age"):
|
| 87 |
# Calculate years
|
| 88 |
years = current_date.year - dob.year
|
| 89 |
if (current_date.month, current_date.day) < (dob.month, dob.day):
|
|
|
|
| 105 |
last_day_of_prev_month = (current_date.replace(day=1) - datetime.timedelta(days=1)).day
|
| 106 |
days = last_day_of_prev_month - dob.day + current_date.day
|
| 107 |
|
| 108 |
+
# Display age details
|
| 109 |
st.write(f"Your date of birth is {dob.strftime('%Y-%m-%d')} and today's date is {current_date.strftime('%Y-%m-%d')}.")
|
| 110 |
st.write(f"Your age is {years} years, {months} months, and {days} days.")
|
| 111 |
|