Akj2023 commited on
Commit
3b2dbaf
·
1 Parent(s): 70e7bca

Add a loading UI Spinner

Browse files
Files changed (2) hide show
  1. app.py +32 -19
  2. templates/mapping.py +0 -1
app.py CHANGED
@@ -90,6 +90,10 @@ with st.sidebar:
90
 
91
  # Main page layout
92
  st.header('Your Itinerary')
 
 
 
 
93
  if submit:
94
  missing_fields = []
95
 
@@ -129,25 +133,34 @@ if submit:
129
  'accommodation': accommodation,
130
  'schedule': schedule
131
  }
132
-
133
- # Display user details in the Streamlit console
134
- st.write("Start Location:", user_details['start_location'])
135
- st.write("End Location:", user_details['end_location'])
136
- st.write("Start Date:", user_details['start_date'])
137
- st.write("End Date:", user_details['end_date'])
138
- st.write("Attractions:", user_details['attractions'])
139
- st.write("Budget:", user_details['budget'])
140
- st.write("Transportation:", user_details['transportation'])
141
- st.write("Accommodation:", user_details['accommodation'])
142
- st.write("Schedule:", user_details['schedule'])
143
-
144
- # Call the generate_itinerary method
145
- itinerary_result = agent.generate_itinerary(user_details)
146
-
147
- # Display the itinerary result or handle it as needed
148
- st.write("Itinerary Suggestion:", itinerary_result["itinerary_suggestion"])
149
- st.write("List of Places:", itinerary_result["list_of_places"])
150
- st.write("Validation Dict:", itinerary_result["validation_dict"])
 
 
 
 
 
 
 
 
 
151
 
152
  note = """Here is your personalized travel itinerary covering all the major locations you want to visit.
153
  This map gives you a general overview of your travel route from start to finish.
 
90
 
91
  # Main page layout
92
  st.header('Your Itinerary')
93
+
94
+ # Create a loading placeholder
95
+ loading_placeholder = st.empty()
96
+
97
  if submit:
98
  missing_fields = []
99
 
 
133
  'accommodation': accommodation,
134
  'schedule': schedule
135
  }
136
+ # Display loading spinner while generating the itinerary
137
+ with loading_placeholder.spinner("Generating itinerary..."):
138
+
139
+ # Call the generate_itinerary method (without artificial delay)
140
+ itinerary_result = agent.generate_itinerary(user_details)
141
+
142
+ if itinerary_result and itinerary_result["itinerary_suggestion"]:
143
+ # Remove the loading spinner
144
+ loading_placeholder.empty()
145
+
146
+ # Display the itinerary and other information (same as before)
147
+ st.subheader("Itinerary Suggestion")
148
+ st.write(itinerary_result["itinerary_suggestion"])
149
+ st.write("List of Places:", itinerary_result["list_of_places"])
150
+ st.write("Validation Dict:", itinerary_result["validation_dict"])
151
+
152
+ elif itinerary_result and itinerary_result["itinerary_suggestion"] is None:
153
+ # Remove the loading spinner
154
+ loading_placeholder.empty()
155
+
156
+ # Display a message for unrealistic edge cases (same as before)
157
+ st.error("The travel plan is not valid.")
158
+ else:
159
+ # Remove the loading spinner
160
+ loading_placeholder.empty()
161
+
162
+ # Handle other errors (same as before)
163
+ st.error("An error occurred while generating the itinerary.")
164
 
165
  note = """Here is your personalized travel itinerary covering all the major locations you want to visit.
166
  This map gives you a general overview of your travel route from start to finish.
templates/mapping.py CHANGED
@@ -31,7 +31,6 @@ class MappingTemplate(object):
31
  For example:
32
 
33
  ####
34
- Itinerary for a 2-day driving trip within London:
35
  - Day 1:
36
  - Start at Buckingham Palace (The Mall, London SW1A 1AA)
37
  - Visit the Tower of London (Tower Hill, London EC3N 4AB)
 
31
  For example:
32
 
33
  ####
 
34
  - Day 1:
35
  - Start at Buckingham Palace (The Mall, London SW1A 1AA)
36
  - Visit the Tower of London (Tower Hill, London EC3N 4AB)