Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing the first version of the travel planner based on Gradio a… #509

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions integrations/crewai/travel_planner_crew_sambanova/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Planner
emoji: 🌍
colorFrom: red
colorTo: green
sdk: gradio
sdk_version: 5.1.0
app_file: app.py
pinned: false
license: mit
short_description: Plan your itinerary with the help of AI
---
2 changes: 2 additions & 0 deletions integrations/crewai/travel_planner_crew_sambanova/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a demonstration of how a travel planner can be built using Agentic AI. Tools used include Gradio, Crew AI, and the backend supported by Sambanova Cloud.
You can test how this works at: https://huggingface.co/spaces/sambanovasystems/trip-planner
154 changes: 154 additions & 0 deletions integrations/crewai/travel_planner_crew_sambanova/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/usr/bin/env python
"""
Travel planner based on Agentic AI workflow.

This module deploys a portal which can customize a day to day travel itinerary
for a person using multiple specialized AI crews.

Implemented using Gradio and Crew AI
A deployment is available at https://huggingface.co/spaces/sambanovasystems/trip-planner
"""

import json
import logging
from typing import List, Tuple

import gradio as gr
import plotly.graph_objects as go
from crew import AddressSummaryCrew, TravelCrew


def filter_map(text_list: List[str], lat: List[str], lon: List[str]) -> go.Figure:
"""
Create a Map showing the points specified in the inputs.

Args:
text_list: List of the description of all locations that will be shown on the map
lat: List of latitude coordinates of the locations
lon: List of longitude coordinates of the locations

Returns:
Figure: Map with the points specified in the inputs
"""

fig = go.Figure(
go.Scattermapbox(lat=lat, lon=lon, mode='markers', marker=go.scattermapbox.Marker(size=11), hovertext=text_list)
)

fig.update_layout(
mapbox_style='open-street-map',
hovermode='closest',
mapbox=dict(bearing=0, center=go.layout.mapbox.Center(lat=lat[1], lon=lon[1]), pitch=0, zoom=10),
)
return fig


def run(
origin: str,
destination: str,
age: int,
trip_duration: int,
interests: List[str],
cuisine_preferences: List[str],
children: bool,
budget: int,
) -> Tuple[str, go.Figure]:
"""
Run the specfied query using Crew AI agents

Args:
origin: Origin city of the traveller
destination: Destination that traveller is going to
age: Age profile of traveller
interests: Specific interests of the traveller
cuisine_preferences: Specific cuisine preferences of the traveller
children: Whether traveller has children travelling with them
budget: Total budget of traveller in US Dollars

Returns:
Returns a tuple containing the itinerary and map
"""
logger.info(
f'Origin: {origin}, Destination: {destination}, Age: {age}, Duration: {trip_duration},'
f' Interests: {interests}, Cuisines: {cuisine_preferences}, Children: {children}, Daily Budget: {budget}'
)
inputs = {
'origin': origin,
'destination': destination,
'age': age,
'trip_duration': trip_duration,
'interests': interests,
'cuisine_preferences': cuisine_preferences,
'children': children,
'budget': budget,
}
result = TravelCrew().crew().kickoff(inputs=inputs)
inputs_for_address = {'text': str(result)}

addresses = AddressSummaryCrew().crew().kickoff(inputs=inputs_for_address)
json_addresses = None
if addresses.json_dict:
json_addresses = addresses.json_dict
if not json_addresses:
try:
json_addresses = json.loads(addresses.raw)
except json.JSONDecodeError as e:
# Try with different format of result data generated with ```json and ending with ```
try:
json_addresses = json.loads(addresses.raw[8:-4])
except json.JSONDecodeError as e:
# Try with different format of result data generated with ``` and ending with ```
try:
json_addresses = json.loads(addresses.raw[4:-4])
except json.JSONDecodeError as e:
logger.error('Error loading Crew Output for addresses')
logger.info(addresses.raw)
return (result, None)
fig = filter_map(json_addresses['name'], json_addresses['lat'], json_addresses['lon'])
return (result, fig)


logger = logging.getLogger()
logger.setLevel(logging.INFO)

demo = gr.Interface(
title='Plan your itinerary with the help of AI',
description='Use this app to create a detailed itinerary on how to explore a new place.'
' Itinerary is customized to your taste. Powered by Sambanova Cloud.',
fn=run,
inputs=[
gr.Textbox(label='Where are you travelling from?'),
gr.Textbox(label='Where are you going?'),
gr.Slider(label='Your age?', value=30, minimum=15, maximum=90, step=5),
gr.Slider(label='How many days are you travelling?', value=5, minimum=1, maximum=14, step=1),
gr.CheckboxGroup(
['Museums', 'Shopping', 'Entertainment', 'Nightlife', 'Outdoor Adventures'],
label='Checkbox your specific interests.',
),
gr.CheckboxGroup(
[
'Ethnic',
'American',
'Italian',
'Mexican',
'Chinese',
'Japanese',
'Indian',
'Thai',
'French',
'Vietnamese',
'Vegan',
],
label='Checkbox your cuisine preferences.',
),
gr.Checkbox(label='Check if children are travelling with you'),
gr.Slider(
label='Total budget of trip in USD', show_label=True, value=1000, minimum=500, maximum=10000, step=500
),
],
outputs=[
gr.Textbox(label='Complete Personalized Itinerary of your Trip', show_copy_button=True, autoscroll=False),
gr.Plot(label='Venues on a Map. Please verify with a Navigation System before traveling.'),
],
)
demo.launch()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
address_summarizer:
role: >
Summarize Addresses into Latitude and Longitude coordinates
goal: >
You need to extract addresses from a provided text and convert those addresses into latitude and longitude coordinates so that they can be easily shown on a map
backstory: >
You are skilled at extracting addresses from lines of text into latitude and longitude coordinates

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
address_compilation_task:
description: >
Extract the list of addresses from {text} in convert them to latitudes and longitudes.

expected_output: >
Output is expected in simple JSON format with three lists. The first list should contain the name of the venue or the name of the restaurant or the activity and should be indexed by the keyword "name". The second list should contain the latitudes and indexed with the keyword "lat". The third list should contain the longitudes and indexed with the keyword "lon".
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
personalized_activity_planner:
role: >
Activity Planner
goal: >
Research and find cool things to do at the destination, including activities and events that match the traveler's interests and age group. Create detailed notes on the activity or event.
backstory: >
You are skilled at creating personalized itineraries that cater to the specific preferences and demographics of travelers.

restaurant_scout:
role: >
Restaurant Scout
goal: >
Find highly-rated restaurants and dining experiences including off-the-beat options at the destination, and recommend scenic locations and fun activities
backstory: >
As a food lover, you know the best spots in town for a delightful culinary experience. You also have a knack for finding picturesque and entertaining locations.

interest_scout:
role: >
Interest Scout
goal: >
Find well-known as well as off-the-beat activities tailored to the list of interests of the traveller and matching the age profile. Also pay particular attention to if there are children. If children are accompanying, pick up activities which might be more interesting to children.
backstory: >
You know the best museums in town for different age groups. Older people may like quieter museums such as art museums. Young children like museums where they can get to touch, feel, and play.

itinerary_compiler:
role: >
Itinerary Compiler
goal: >
Compile all researched information into a comprehensive day-by-day itinerary, ensuring the integration of flights and hotel information. Recommend at least three hotels, one in budget price range, one in medium price range, and one five star top end hotel.
backstory: >
With an eye for detail, you organize all the information into a coherent and enjoyable travel plan.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
personalized_activity_planning_task:
description: >
Research and find cool things to do at {destination}.
Focus on activities and events that match the traveler's interests and age group.
Utilize internet search tools and recommendation engines to gather the information.

Traveler's information:

- origin: {origin}

- destination: {destination}

- Approximate age of the adult travelers: {age}

- List of interests that the traveller may have: {interests}

- List of cuisine preferences that the traveller may have: {cuisine_preferences}

- Are children accompanying the trip: {children}

- how long is the trip: {trip_duration}

- budget for entire trip in dollars: {budget}
expected_output: >
A list of recommended activities and events for each day of the trip.
Each entry should include the activity name, location including a , a brief description, and why it's suitable for the traveler.
The location should have the full address so that it can be easily found using a map.
And potential reviews and ratings of the activities.

restaurant_scenic_location_scout_task:
description: >
Find highly-rated restaurants and dining experiences for the specific cuisine interests {cuisine_preferences} at {destination}.
Pay particular attention to the cuisines. If Vegan is on the list, then recommend restaurants which accomodate vegan diet.
Recommend scenic locations that align with the traveler's preferences and activities.
Use internet search tools, restaurant review sites, and travel guides.
Make sure to find a variety of options to suit different tastes and budgets, and ratings for them.
Extract the address of he restaurant so that the same can be displayed to the user.

Traveler's information:

- origin: {origin}

- destination: {destination}

- age of the traveler: {age}

- List of cuisine preferences that the traveller may have: {cuisine_preferences}

- how long is the trip: {trip_duration}

- budget for entire trip in dollars: {budget}
expected_output: >
A list of recommended restaurants for each day of the trip.
Each entry should include the name, location including a detailed address, type of cuisine or activity, and a brief description and ratings.

interest_scout_task:
description: >
Run specifically for the interests of the traveller provided {interests}. As an example if the traveller has interest in museums, plan activities related to museums at the destination.
Check if children are accompanying in the trip. {children}
If children are accompanying, find activities that might be more appealing to children.
Use internet search tools, review sites, feedback from users, and travel guides.
Extract the address of the activity so that the same can be displayed to the user.

Traveler's information:

- origin: {origin}

- destination: {destination}

- age of the traveler: {age}

- List of interests that the traveller may have: {interests}

- Are children accompanying the trip: {children}

- how long is the trip: {trip_duration}

- budget for entire trip in dollars: {budget}
expected_output: >
A list of recommended activities. There must be at least one activity for each day of the trip. Allocate appropriate time for the activity so that the traveller need not rush to the next activity.
Each entry should include the name, location including a detailed address, type of cuisine or activity, and a brief description and ratings.


itinerary_compilation_task:
description: >
Compile all researched information into a comprehensive day-by-day itinerary for the trip to {destination}.
Include information relevant to the traveler's interests. For example, if the traveller is not interested in museums, do not pack the itinerary with museums.
Ensure the itinerary integrates hotel information and all planned activities and dining experiences.
Make sure that you do not recommend the same restaurant for both lunch and dinner.
Use text formatting and document creation tools to organize the information.
Do a great job so that you can be proud of your work.
expected_output: >
A detailed itinerary document, the itinerary should include a day-by-day
plan with activities, restaurants, and scenic locations. Include the address for each location so that an user can easily go to the address. A day can contain multiple activities. In such a case a recommened mode of transport should be provided to help move from one activity location to another.
Loading
Loading