Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,52 @@
|
|
1 |
import streamlit as st
|
2 |
from datetime import datetime, timedelta
|
|
|
3 |
|
4 |
# App Title and Description
|
5 |
-
st.title("π Age Calculator")
|
6 |
st.write("""
|
7 |
-
Calculate your age in years,
|
8 |
See your next 5 birthdays and get a detailed textual output in English.
|
9 |
""")
|
10 |
|
11 |
-
# Input
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
if dob:
|
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 |
# Footer
|
50 |
st.write("---")
|
|
|
1 |
import streamlit as st
|
2 |
from datetime import datetime, timedelta
|
3 |
+
from dateutil.relativedelta import relativedelta
|
4 |
|
5 |
# App Title and Description
|
6 |
+
st.title("π Advanced Age Calculator")
|
7 |
st.write("""
|
8 |
+
Calculate your age in years, months, and days!
|
9 |
See your next 5 birthdays and get a detailed textual output in English.
|
10 |
""")
|
11 |
|
12 |
+
# Input Section
|
13 |
+
if st.button("Click to Enter Your Date of Birth"):
|
14 |
+
dob = st.date_input("Select Your Date of Birth (YYYY-MM-DD):")
|
15 |
+
|
16 |
+
if dob:
|
17 |
+
# Calculate Age
|
18 |
+
today = datetime.now()
|
19 |
+
dob_datetime = datetime.combine(dob, datetime.min.time())
|
20 |
+
age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
|
21 |
+
age_months = relativedelta(today, dob_datetime).months
|
22 |
+
age_days = (today - dob_datetime).days % 30 # Approximation for days in the current month
|
23 |
+
|
24 |
+
# Next 5 Birthdays
|
25 |
+
next_birthdays = []
|
26 |
+
next_birthday = datetime(today.year, dob.month, dob.day)
|
27 |
+
if next_birthday < today:
|
28 |
+
next_birthday = datetime(today.year + 1, dob.month, dob.day)
|
29 |
+
|
30 |
+
for _ in range(5):
|
31 |
+
next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
|
32 |
+
next_birthday = next_birthday.replace(year=next_birthday.year + 1)
|
33 |
+
|
34 |
+
if st.button("Calculate Age and Next Birthdays"):
|
35 |
+
# Display Age
|
36 |
+
st.subheader("π Your Age:")
|
37 |
+
st.write(f"**Years:** {age_years}")
|
38 |
+
st.write(f"**Months:** {age_months}")
|
39 |
+
st.write(f"**Days:** {age_days}")
|
40 |
+
|
41 |
+
# Display Next 5 Birthdays
|
42 |
+
st.subheader("π Next 5 Birthdays:")
|
43 |
+
for idx, birthday in enumerate(next_birthdays, start=1):
|
44 |
+
st.write(f"{idx}. {birthday}")
|
45 |
+
|
46 |
+
# English Textual Output
|
47 |
+
st.subheader("π Age in English:")
|
48 |
+
st.write(f"You are **{age_years} years, {age_months} months, and {age_days} days old**.")
|
49 |
+
st.write("Your next five birthdays will be on the dates listed above.")
|
50 |
|
51 |
# Footer
|
52 |
st.write("---")
|