Spaces:
Sleeping
Sleeping
Abdulla Fahem
commited on
Commit
·
dc8d270
1
Parent(s):
ba88fc0
Update application file
Browse files
app.py
CHANGED
@@ -298,7 +298,7 @@ def generate_fallback_plan(destination, days, interests, budget):
|
|
298 |
- budget: Trip budget category
|
299 |
|
300 |
Returns:
|
301 |
-
A formatted travel plan string
|
302 |
"""
|
303 |
# Basic activity templates
|
304 |
basic_activities = {
|
@@ -314,21 +314,26 @@ def generate_fallback_plan(destination, days, interests, budget):
|
|
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 = []
|
325 |
available_interests = interests[:2] # Use up to 2 interests per day
|
326 |
|
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 = {
|
@@ -343,68 +348,44 @@ def generate_fallback_plan(destination, days, interests, budget):
|
|
343 |
travel_plan_lines.append("") # Add blank line between days
|
344 |
|
345 |
# Create a travel plan string
|
346 |
-
|
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(
|
361 |
"""
|
362 |
-
Format travel plan
|
363 |
|
364 |
Parameters:
|
365 |
-
-
|
366 |
- destination: Target destination
|
367 |
- days: Number of trip days
|
368 |
-
- interests: Optional interests
|
369 |
-
- budget: Optional budget
|
370 |
|
371 |
Returns:
|
372 |
Formatted travel plan as a string
|
373 |
"""
|
374 |
-
#
|
375 |
-
|
376 |
-
|
377 |
-
(sample_data['days'] == days)
|
378 |
-
]
|
379 |
-
|
380 |
-
# Apply additional filters if provided
|
381 |
-
if interests:
|
382 |
-
filtered_data = filtered_data[filtered_data['interests'] == interests]
|
383 |
-
|
384 |
-
if budget:
|
385 |
-
filtered_data = filtered_data[filtered_data['budget'] == budget]
|
386 |
|
387 |
-
#
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
formatted_plan.append(selected_plan['travel_plan'])
|
406 |
-
|
407 |
-
return "\n".join(formatted_plan)
|
408 |
|
409 |
|
410 |
def main():
|
|
|
298 |
- budget: Trip budget category
|
299 |
|
300 |
Returns:
|
301 |
+
A formatted travel plan string
|
302 |
"""
|
303 |
# Basic activity templates
|
304 |
basic_activities = {
|
|
|
314 |
}
|
315 |
|
316 |
# Prepare the travel plan
|
317 |
+
travel_plan_lines = [
|
318 |
+
f"# Travel Plan Details",
|
319 |
+
f"## Destination: {destination}",
|
320 |
+
f"## Duration: {days} days",
|
321 |
+
f"## Interests: {', '.join(interests)}",
|
322 |
+
f"## Budget: {budget}\n",
|
323 |
+
"## Itinerary:\n"
|
324 |
+
]
|
325 |
|
326 |
# Generate activities for each day
|
327 |
for day in range(1, days + 1):
|
328 |
day_lines = [f"Day {day}:"]
|
329 |
|
330 |
# Select activities based on interests
|
|
|
331 |
available_interests = interests[:2] # Use up to 2 interests per day
|
332 |
|
333 |
for interest in available_interests:
|
334 |
if interest in basic_activities:
|
335 |
activity = random.choice(basic_activities[interest])
|
336 |
day_lines.append(f"- {activity}")
|
|
|
337 |
|
338 |
# Add budget-specific note
|
339 |
budget_text = {
|
|
|
348 |
travel_plan_lines.append("") # Add blank line between days
|
349 |
|
350 |
# Create a travel plan string
|
351 |
+
return "\n".join(travel_plan_lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
+
def format_travel_plan(travel_plan, destination, days, interests=None, budget=None):
|
354 |
"""
|
355 |
+
Format travel plan string
|
356 |
|
357 |
Parameters:
|
358 |
+
- travel_plan: Generated travel plan string
|
359 |
- destination: Target destination
|
360 |
- days: Number of trip days
|
361 |
+
- interests: Optional interests (default: None)
|
362 |
+
- budget: Optional budget (default: None)
|
363 |
|
364 |
Returns:
|
365 |
Formatted travel plan as a string
|
366 |
"""
|
367 |
+
# If the input is already a properly formatted string, return it
|
368 |
+
if isinstance(travel_plan, str):
|
369 |
+
return travel_plan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
+
# If it's a DataFrame or Series, extract the travel plan
|
372 |
+
try:
|
373 |
+
# Attempt to get the travel plan from DataFrame or Series
|
374 |
+
if hasattr(travel_plan, 'iloc'):
|
375 |
+
# If it's a DataFrame or Series, get the first row's travel plan
|
376 |
+
travel_plan = travel_plan.iloc[0]['travel_plan']
|
377 |
+
elif hasattr(travel_plan, 'get'):
|
378 |
+
# If it's a dictionary-like object
|
379 |
+
travel_plan = travel_plan.get('travel_plan', '')
|
380 |
+
except Exception:
|
381 |
+
# Fallback to generating a new plan if extraction fails
|
382 |
+
return generate_fallback_plan(destination, days, interests or [], budget or 'Moderate')
|
383 |
+
|
384 |
+
# Ensure travel_plan is a string
|
385 |
+
if not isinstance(travel_plan, str):
|
386 |
+
return generate_fallback_plan(destination, days, interests or [], budget or 'Moderate')
|
387 |
+
|
388 |
+
return travel_plan
|
|
|
|
|
|
|
389 |
|
390 |
|
391 |
def main():
|