Spaces:
Runtime error
Runtime error
Fix end data issue
Browse files
app.py
CHANGED
@@ -4,20 +4,18 @@ from datetime import datetime, timedelta, date
|
|
4 |
# Title of the application
|
5 |
st.title('Smart Travel Itinerary Suggester')
|
6 |
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
if 'start_date' not in st.session_state:
|
9 |
st.session_state['start_date'] = datetime.today()
|
10 |
|
11 |
if 'end_date' not in st.session_state:
|
12 |
-
st.session_state['end_date'] =
|
13 |
-
|
14 |
-
|
15 |
-
def update_end_date():
|
16 |
-
# Only update end_date if it is not None and the start_date is equal to or after the current end_date
|
17 |
-
if 'end_date' in st.session_state and st.session_state['end_date'] is not None:
|
18 |
-
if st.session_state['start_date'] >= st.session_state['end_date']:
|
19 |
-
# Set the end_date in the session state to one day after the new start_date
|
20 |
-
st.session_state['end_date'] = st.session_state['start_date'] + timedelta(days=1)
|
21 |
|
22 |
# Sidebar for input
|
23 |
with st.sidebar:
|
@@ -29,13 +27,13 @@ with st.sidebar:
|
|
29 |
# Travel Dates input
|
30 |
today = date.today()
|
31 |
|
32 |
-
#
|
33 |
start_date = st.date_input(
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
)
|
40 |
|
41 |
end_date = st.date_input(
|
@@ -46,9 +44,13 @@ with st.sidebar:
|
|
46 |
help='End Date must be after the Start Date.'
|
47 |
)
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Preferences multiselect
|
54 |
attractions = st.multiselect(
|
|
|
4 |
# Title of the application
|
5 |
st.title('Smart Travel Itinerary Suggester')
|
6 |
|
7 |
+
# Callback function to update the end date
|
8 |
+
def update_end_date():
|
9 |
+
if st.session_state.end_date <= st.session_state.start_date:
|
10 |
+
# Update the end date in session state to be one day after the start date
|
11 |
+
st.session_state.end_date = st.session_state.start_date + timedelta(days=1)
|
12 |
+
|
13 |
+
# Set default values for start_date and end_date in session state if not already set
|
14 |
if 'start_date' not in st.session_state:
|
15 |
st.session_state['start_date'] = datetime.today()
|
16 |
|
17 |
if 'end_date' not in st.session_state:
|
18 |
+
st.session_state['end_date'] = st.session_state['start_date'] + timedelta(days=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Sidebar for input
|
21 |
with st.sidebar:
|
|
|
27 |
# Travel Dates input
|
28 |
today = date.today()
|
29 |
|
30 |
+
# Create the start date input widget
|
31 |
start_date = st.date_input(
|
32 |
+
'Start Date',
|
33 |
+
min_value=datetime.today(),
|
34 |
+
value=st.session_state.start_date,
|
35 |
+
key='start_date', # Link this widget to the start_date in session state
|
36 |
+
on_change=update_end_date # Callback function to call when this date input changes
|
37 |
)
|
38 |
|
39 |
end_date = st.date_input(
|
|
|
44 |
help='End Date must be after the Start Date.'
|
45 |
)
|
46 |
|
47 |
+
# Create the end date input widget
|
48 |
+
end_date = st.date_input(
|
49 |
+
'End Date',
|
50 |
+
min_value=st.session_state.start_date + timedelta(days=1),
|
51 |
+
value=st.session_state.end_date,
|
52 |
+
key='end_date' # Link this widget to the end_date in session state
|
53 |
+
)
|
54 |
|
55 |
# Preferences multiselect
|
56 |
attractions = st.multiselect(
|