Abdulla Fahem commited on
Commit
3e4d2df
Β·
1 Parent(s): 07913c3

Add application file

Browse files
Files changed (1) hide show
  1. app.py +98 -56
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 to ensure exact number of days and proper formatting"""
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
- formatted_plan.append((current_day, '\n'.join(current_activities)))
 
 
 
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
- formatted_plan.append((current_day, '\n'.join(current_activities)))
 
 
 
373
 
374
  # Sort days and ensure we have exactly the requested number of days
375
- formatted_plan.sort(key=lambda x: x[0])
376
- final_plan = []
377
 
378
- # Generate the final formatted plan with exactly the requested number of days
379
  for day in range(1, days + 1):
380
  # Find the matching day's activities or use a placeholder
381
- day_content = next((content for d, content in formatted_plan if d == day),
382
- "Explore local attractions and sights")
383
- final_plan.append(f"Day {day}:\n{day_content}\n")
 
 
 
 
 
 
 
 
 
 
 
384
 
385
- # Join all days with proper spacing
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
- with st.spinner("Loading AI model... Please wait..."):
424
- model, tokenizer = load_or_train_model()
425
- if model is None or tokenizer is None:
426
- st.error("Failed to load/train the AI model. Please try again.")
427
- return
428
- st.session_state.model = model
429
- st.session_state.tokenizer = tokenizer
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
- st.success("✨ Your travel plan is ready!")
 
 
 
 
 
 
 
 
 
 
517
 
518
- # Display the plan in tabs
519
- plan_tab, summary_tab = st.tabs(["πŸ“‹ Travel Plan", "ℹ️ Trip Summary"])
520
 
521
  with plan_tab:
522
- st.markdown(travel_plan)
523
-
524
- # Add export options
525
- st.download_button(
526
- label="πŸ“₯ Download Plan",
527
- data=travel_plan,
528
- file_name=f"travel_plan_{destination.lower().replace(' ', '_')}.md",
529
- mime="text/markdown"
530
- )
 
 
 
 
 
 
 
 
 
 
 
 
531
 
532
  with summary_tab:
533
- # Create three columns for summary information
534
- sum_col1, sum_col2, sum_col3 = st.columns(3)
535
-
536
- with sum_col1:
537
- st.markdown("### πŸ“ Destination")
538
- st.markdown(f"**{destination}**")
539
- st.markdown("### ⏱️ Duration")
540
- st.markdown(f"**{days} days**")
541
-
542
- with sum_col2:
543
- st.markdown("### πŸ’° Budget")
544
- st.markdown(f"**{budget}**")
545
- st.markdown("### 🎯 Interests")
546
- for interest in interests:
547
- st.markdown(f"- {interest}")
548
-
549
- with sum_col3:
550
- st.markdown("### ⚠️ Important Notes")
551
- st.info(
552
- "- Verify opening hours\n"
553
- "- Check current prices\n"
554
- "- Confirm availability\n"
555
- "- Consider seasonal factors"
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()