Abdulla Fahem commited on
Commit
ba88fc0
·
1 Parent(s): 8044a82

Update application file

Browse files
Files changed (1) hide show
  1. app.py +37 -15
app.py CHANGED
@@ -16,7 +16,6 @@ from torch.utils.data import Dataset
16
  from datetime import datetime
17
  import numpy as np
18
  from random import choice
19
- import re
20
 
21
  class TravelDataset(Dataset):
22
  def __init__(self, data, tokenizer, max_length=512):
@@ -289,10 +288,18 @@ def generate_travel_plan(destination, days, interests, budget, model, tokenizer)
289
  return fallback_plan
290
 
291
  def generate_fallback_plan(destination, days, interests, budget):
292
- """Generate a basic fallback plan if the model fails"""
293
- # Start with the overview section
294
- fallback_plan = f"# Emergency Travel Plan for {destination}\n\n"
 
 
 
 
 
295
 
 
 
 
296
  # Basic activity templates
297
  basic_activities = {
298
  'Culture': ['Visit museums', 'Explore historical sites', 'Attend local events'],
@@ -306,9 +313,12 @@ def generate_fallback_plan(destination, days, interests, budget):
306
  'Museums': ['Visit main museums', 'Join guided tours', 'See special exhibits']
307
  }
308
 
309
- # Generate exactly the requested number of days
 
 
 
310
  for day in range(1, days + 1):
311
- fallback_plan += f"\nDay {day}:\n"
312
 
313
  # Select activities based on interests
314
  day_activities = []
@@ -317,23 +327,35 @@ def generate_fallback_plan(destination, days, interests, budget):
317
  for interest in available_interests:
318
  if interest in basic_activities:
319
  activity = random.choice(basic_activities[interest])
 
320
  day_activities.append(activity)
321
 
322
- # Add budget-appropriate text
323
  budget_text = {
324
  'Budget': 'Focus on free and affordable activities',
325
  'Moderate': 'Mix of affordable and premium experiences',
326
  'Luxury': 'Premium experiences and exclusive access'
327
- }.get(budget, '')
 
 
328
 
329
- # Format the day's activities
330
- fallback_plan += f"Morning: {day_activities[0] if day_activities else 'Explore the area'}\n"
331
- if len(day_activities) > 1:
332
- fallback_plan += f"Afternoon/Evening: {day_activities[1]}\n"
333
- fallback_plan += f"Note: {budget_text}\n"
 
 
 
 
 
 
 
 
 
334
 
335
- # Format the fallback plan using the same formatter
336
- return format_travel_plan(fallback_plan, destination, days)
337
 
338
  def format_travel_plan(sample_data, destination, days, interests=None, budget=None):
339
  """
 
16
  from datetime import datetime
17
  import numpy as np
18
  from random import choice
 
19
 
20
  class TravelDataset(Dataset):
21
  def __init__(self, data, tokenizer, max_length=512):
 
288
  return fallback_plan
289
 
290
  def generate_fallback_plan(destination, days, interests, budget):
291
+ """
292
+ Generate a basic fallback travel plan if the model fails
293
+
294
+ Parameters:
295
+ - destination: Target travel destination
296
+ - days: Number of days for the trip
297
+ - interests: Primary interests for the trip
298
+ - budget: Trip budget category
299
 
300
+ Returns:
301
+ A formatted travel plan string compatible with format_travel_plan function
302
+ """
303
  # Basic activity templates
304
  basic_activities = {
305
  'Culture': ['Visit museums', 'Explore historical sites', 'Attend local events'],
 
313
  'Museums': ['Visit main museums', 'Join guided tours', 'See special exhibits']
314
  }
315
 
316
+ # Prepare the travel plan
317
+ travel_plan_lines = []
318
+
319
+ # Generate activities for each day
320
  for day in range(1, days + 1):
321
+ day_lines = [f"Day {day}:"]
322
 
323
  # Select activities based on interests
324
  day_activities = []
 
327
  for interest in available_interests:
328
  if interest in basic_activities:
329
  activity = random.choice(basic_activities[interest])
330
+ day_lines.append(f"- {activity}")
331
  day_activities.append(activity)
332
 
333
+ # Add budget-specific note
334
  budget_text = {
335
  'Budget': 'Focus on free and affordable activities',
336
  'Moderate': 'Mix of affordable and premium experiences',
337
  'Luxury': 'Premium experiences and exclusive access'
338
+ }.get(budget, 'Balanced travel experiences')
339
+
340
+ day_lines.append(f"Note: {budget_text}")
341
 
342
+ travel_plan_lines.extend(day_lines)
343
+ travel_plan_lines.append("") # Add blank line between days
344
+
345
+ # Create a travel plan string
346
+ travel_plan_str = "\n".join(travel_plan_lines)
347
+
348
+ # Create a temporary DataFrame to simulate the CSV data structure
349
+ df = pd.DataFrame({
350
+ 'destination': [destination],
351
+ 'days': [days],
352
+ 'interests': [', '.join(interests)],
353
+ 'budget': [budget],
354
+ 'travel_plan': [travel_plan_str]
355
+ })
356
 
357
+ # Use format_travel_plan to format the fallback plan
358
+ return format_travel_plan(df, destination, days, ', '.join(interests), budget)
359
 
360
  def format_travel_plan(sample_data, destination, days, interests=None, budget=None):
361
  """