safiaa02 commited on
Commit
a4c8bb9
Β·
verified Β·
1 Parent(s): 6e05e55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -11
app.py CHANGED
@@ -2,25 +2,76 @@ import streamlit as st
2
  from datetime import date
3
  from dateutil.relativedelta import relativedelta
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  # App Title
6
- st.set_page_config(page_title="Age Calculator", page_icon="πŸŽ‚")
7
- st.title("πŸŽ‚ Age Calculator")
8
 
9
- # User Input with extended range
10
- birth_date = st.date_input(
11
- "Enter your birth date:",
12
- min_value=date(1950, 1, 1),
13
- max_value=date.today()
14
- )
 
15
 
16
  # Current Date
17
  today = date.today()
18
 
 
19
  if birth_date > today:
20
  st.error("Your birth date can't be in the future.")
21
  else:
22
- # Calculate difference
23
  difference = relativedelta(today, birth_date)
24
 
25
- # Display Results
26
- st.success(f"Your age is **{difference.years}** years, **{difference.months}** months, and **{difference.days}** days.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from datetime import date
3
  from dateutil.relativedelta import relativedelta
4
 
5
+ # App Config
6
+ st.set_page_config(page_title="πŸŽ‚ Age Calculator", page_icon="πŸŽ‰", layout="centered")
7
+
8
+ # Custom CSS
9
+ st.markdown("""
10
+ <style>
11
+ .main {
12
+ background-color: #fff5f8;
13
+ padding: 2rem;
14
+ border-radius: 1rem;
15
+ box-shadow: 0px 0px 20px rgba(0,0,0,0.1);
16
+ }
17
+ .title {
18
+ font-size: 3em;
19
+ color: #FF69B4;
20
+ text-align: center;
21
+ margin-bottom: 1rem;
22
+ }
23
+ .result {
24
+ font-size: 1.5em;
25
+ color: #4B0082;
26
+ text-align: center;
27
+ margin-top: 1.5rem;
28
+ }
29
+ .birthday {
30
+ font-size: 1.3em;
31
+ color: #32CD32;
32
+ text-align: center;
33
+ margin-top: 1rem;
34
+ }
35
+ </style>
36
+ """, unsafe_allow_html=True)
37
+
38
  # App Title
39
+ st.markdown('<div class="title">πŸŽ‚ Age Calculator</div>', unsafe_allow_html=True)
 
40
 
41
+ # Input Section
42
+ with st.container():
43
+ birth_date = st.date_input(
44
+ "πŸ“… Select your birth date:",
45
+ min_value=date(1950, 1, 1),
46
+ max_value=date.today()
47
+ )
48
 
49
  # Current Date
50
  today = date.today()
51
 
52
+ # Logic
53
  if birth_date > today:
54
  st.error("Your birth date can't be in the future.")
55
  else:
 
56
  difference = relativedelta(today, birth_date)
57
 
58
+ # Display Age
59
+ st.markdown(f"""
60
+ <div class="main">
61
+ <div class="result">
62
+ 🎈 You are <strong>{difference.years}</strong> years,
63
+ <strong>{difference.months}</strong> months, and
64
+ <strong>{difference.days}</strong> days old!
65
+ </div>
66
+ """, unsafe_allow_html=True)
67
+
68
+ # Birthday greeting
69
+ if birth_date.day == today.day and birth_date.month == today.month:
70
+ st.markdown("""
71
+ <div class="birthday">
72
+ πŸŽ‰ Happy Birthday! πŸŽ‰<br>
73
+ May your year be filled with joy and success!
74
+ </div>
75
+ """, unsafe_allow_html=True)
76
+
77
+ st.markdown("</div>", unsafe_allow_html=True)