Spaces:
Sleeping
Sleeping
Abdulla Fahem
commited on
Commit
Β·
3e4d2df
1
Parent(s):
07913c3
Add application file
Browse files
app.py
CHANGED
@@ -333,8 +333,9 @@ def generate_fallback_plan(destination, days, interests, budget):
|
|
333 |
return format_travel_plan(fallback_plan, days)
|
334 |
|
335 |
def format_travel_plan(plan, days):
|
336 |
-
"""Format the travel plan
|
337 |
formatted_plan = []
|
|
|
338 |
current_day = None
|
339 |
current_activities = []
|
340 |
|
@@ -343,12 +344,15 @@ def format_travel_plan(plan, days):
|
|
343 |
line = line.strip()
|
344 |
if not line:
|
345 |
continue
|
346 |
-
|
347 |
# Check for day headers
|
348 |
if line.lower().startswith('day'):
|
349 |
# Save previous day's activities if they exist
|
350 |
if current_day is not None and current_activities:
|
351 |
-
|
|
|
|
|
|
|
352 |
|
353 |
# Extract day number
|
354 |
try:
|
@@ -369,21 +373,33 @@ def format_travel_plan(plan, days):
|
|
369 |
|
370 |
# Add the last day if there are pending activities
|
371 |
if current_day is not None and current_activities:
|
372 |
-
|
|
|
|
|
|
|
373 |
|
374 |
# Sort days and ensure we have exactly the requested number of days
|
375 |
-
|
376 |
-
final_plan = []
|
377 |
|
378 |
-
# Generate the final formatted plan
|
379 |
for day in range(1, days + 1):
|
380 |
# Find the matching day's activities or use a placeholder
|
381 |
-
day_content = next(
|
382 |
-
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
|
385 |
-
|
386 |
-
return '\n'.join(final_plan)
|
387 |
|
388 |
def main():
|
389 |
st.set_page_config(
|
@@ -419,14 +435,14 @@ def main():
|
|
419 |
""")
|
420 |
|
421 |
# Load or train model
|
422 |
-
if 'model' not in st.session_state:
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
|
431 |
# Create two columns for input form
|
432 |
col1, col2 = st.columns([2, 1])
|
@@ -513,47 +529,73 @@ def main():
|
|
513 |
st.session_state.tokenizer
|
514 |
)
|
515 |
|
516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
|
518 |
-
# Display the plan in tabs
|
519 |
-
plan_tab, summary_tab = st.tabs(["π
|
520 |
|
521 |
with plan_tab:
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
with summary_tab:
|
533 |
-
# Create three columns for summary information
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
|
|
|
|
|
|
|
|
557 |
|
558 |
if __name__ == "__main__":
|
559 |
main()
|
|
|
333 |
return format_travel_plan(fallback_plan, days)
|
334 |
|
335 |
def format_travel_plan(plan, days):
|
336 |
+
"""Format the travel plan with improved readability and structure"""
|
337 |
formatted_plan = []
|
338 |
+
day_sections = []
|
339 |
current_day = None
|
340 |
current_activities = []
|
341 |
|
|
|
344 |
line = line.strip()
|
345 |
if not line:
|
346 |
continue
|
347 |
+
|
348 |
# Check for day headers
|
349 |
if line.lower().startswith('day'):
|
350 |
# Save previous day's activities if they exist
|
351 |
if current_day is not None and current_activities:
|
352 |
+
day_sections.append({
|
353 |
+
'day': current_day,
|
354 |
+
'activities': current_activities
|
355 |
+
})
|
356 |
|
357 |
# Extract day number
|
358 |
try:
|
|
|
373 |
|
374 |
# Add the last day if there are pending activities
|
375 |
if current_day is not None and current_activities:
|
376 |
+
day_sections.append({
|
377 |
+
'day': current_day,
|
378 |
+
'activities': current_activities
|
379 |
+
})
|
380 |
|
381 |
# Sort days and ensure we have exactly the requested number of days
|
382 |
+
day_sections.sort(key=lambda x: x['day'])
|
|
|
383 |
|
384 |
+
# Generate the final formatted plan
|
385 |
for day in range(1, days + 1):
|
386 |
# Find the matching day's activities or use a placeholder
|
387 |
+
day_content = next(
|
388 |
+
(section for section in day_sections if section['day'] == day),
|
389 |
+
{'day': day, 'activities': ["Explore local attractions and sights"]}
|
390 |
+
)
|
391 |
+
|
392 |
+
# Format the day's content with markdown
|
393 |
+
formatted_plan.append(f"### Day {day}\n")
|
394 |
+
|
395 |
+
# Format activities with bullet points
|
396 |
+
for activity in day_content['activities']:
|
397 |
+
formatted_plan.append(f"- {activity}")
|
398 |
+
|
399 |
+
# Add spacing between days
|
400 |
+
formatted_plan.append("\n")
|
401 |
|
402 |
+
return "\n".join(formatted_plan)
|
|
|
403 |
|
404 |
def main():
|
405 |
st.set_page_config(
|
|
|
435 |
""")
|
436 |
|
437 |
# Load or train model
|
438 |
+
# if 'model' not in st.session_state:
|
439 |
+
# with st.spinner("Loading AI model... Please wait..."):
|
440 |
+
# model, tokenizer = load_or_train_model()
|
441 |
+
# if model is None or tokenizer is None:
|
442 |
+
# st.error("Failed to load/train the AI model. Please try again.")
|
443 |
+
# return
|
444 |
+
# st.session_state.model = model
|
445 |
+
# st.session_state.tokenizer = tokenizer
|
446 |
|
447 |
# Create two columns for input form
|
448 |
col1, col2 = st.columns([2, 1])
|
|
|
529 |
st.session_state.tokenizer
|
530 |
)
|
531 |
|
532 |
+
# Create an expander for the success message with trip overview
|
533 |
+
with st.expander("β¨ Your travel plan is ready! Click to see trip overview", expanded=True):
|
534 |
+
col1, col2, col3 = st.columns(3)
|
535 |
+
with col1:
|
536 |
+
st.metric("Destination", destination)
|
537 |
+
with col2:
|
538 |
+
st.metric("Duration", f"{days} days")
|
539 |
+
with col3:
|
540 |
+
st.metric("Budget", budget)
|
541 |
+
|
542 |
+
st.write("**Selected Interests:**", ", ".join(interests))
|
543 |
|
544 |
+
# Display the plan in tabs with improved styling
|
545 |
+
plan_tab, summary_tab = st.tabs(["π Detailed Itinerary", "βΉοΈ Trip Summary"])
|
546 |
|
547 |
with plan_tab:
|
548 |
+
# Add a container for better spacing
|
549 |
+
with st.container():
|
550 |
+
# Add trip title
|
551 |
+
st.markdown(f"## π {days}-Day Trip to {destination}")
|
552 |
+
st.markdown("---")
|
553 |
+
|
554 |
+
# Display the formatted plan
|
555 |
+
st.markdown(travel_plan)
|
556 |
+
|
557 |
+
# Add export options in a nice container
|
558 |
+
with st.container():
|
559 |
+
st.markdown("---")
|
560 |
+
col1, col2 = st.columns([1, 4])
|
561 |
+
with col1:
|
562 |
+
st.download_button(
|
563 |
+
label="π₯ Download Plan",
|
564 |
+
data=travel_plan,
|
565 |
+
file_name=f"travel_plan_{destination.lower().replace(' ', '_')}.md",
|
566 |
+
mime="text/markdown",
|
567 |
+
use_container_width=True
|
568 |
+
)
|
569 |
|
570 |
with summary_tab:
|
571 |
+
# Create three columns for summary information with cards
|
572 |
+
with st.container():
|
573 |
+
st.markdown("## Trip Overview")
|
574 |
+
sum_col1, sum_col2, sum_col3 = st.columns(3)
|
575 |
+
|
576 |
+
with sum_col1:
|
577 |
+
with st.container():
|
578 |
+
st.markdown("### π Destination Details")
|
579 |
+
st.markdown(f"**Location:** {destination}")
|
580 |
+
st.markdown(f"**Duration:** {days} days")
|
581 |
+
st.markdown(f"**Budget Level:** {budget}")
|
582 |
+
|
583 |
+
with sum_col2:
|
584 |
+
with st.container():
|
585 |
+
st.markdown("### π― Trip Focus")
|
586 |
+
st.markdown("**Selected Interests:**")
|
587 |
+
for interest in interests:
|
588 |
+
st.markdown(f"- {interest}")
|
589 |
+
|
590 |
+
with sum_col3:
|
591 |
+
with st.container():
|
592 |
+
st.markdown("### β οΈ Travel Tips")
|
593 |
+
st.info(
|
594 |
+
"β’ Verify opening hours\n"
|
595 |
+
"β’ Check current prices\n"
|
596 |
+
"β’ Confirm availability\n"
|
597 |
+
"β’ Consider seasonal factors"
|
598 |
+
)
|
599 |
|
600 |
if __name__ == "__main__":
|
601 |
main()
|