Spaces:
Running
Running
Initial v0.1 version of the app
Browse files- app.py +27 -0
- config/agents.yaml +23 -0
- config/tasks.yaml +51 -0
- crew.py +118 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
import sys
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from crew import SurpriseTravelCrew
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def run(origin, destination, age, trip_duration):
|
| 8 |
+
# Replace with your inputs, it will automatically interpolate any tasks and agents information
|
| 9 |
+
inputs = {
|
| 10 |
+
'origin': origin,
|
| 11 |
+
'destination': destination,
|
| 12 |
+
'age': age,
|
| 13 |
+
'trip_duration': trip_duration
|
| 14 |
+
}
|
| 15 |
+
result = SurpriseTravelCrew().crew().kickoff(inputs=inputs)
|
| 16 |
+
return (result)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
title="Plan your itinerary with the help of AI",
|
| 21 |
+
description="Use this app to create a detailed itinerary on how to explore a new place. Itinerary is customized to your taste",
|
| 22 |
+
fn=run,
|
| 23 |
+
inputs=["text", "text", gr.Slider(value=30, minimum=15, maximum=90, step=5),
|
| 24 |
+
gr.Slider(value=5, minimum=1, maximum=14, step=1)],
|
| 25 |
+
outputs=["text"],
|
| 26 |
+
)
|
| 27 |
+
demo.launch(share=True)
|
config/agents.yaml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
personalized_activity_planner:
|
| 2 |
+
role: >
|
| 3 |
+
Activity Planner
|
| 4 |
+
goal: >
|
| 5 |
+
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.
|
| 6 |
+
backstory: >
|
| 7 |
+
You are skilled at creating personalized itineraries that cater to the specific preferences and demographics of travelers.
|
| 8 |
+
|
| 9 |
+
restaurant_scout:
|
| 10 |
+
role: >
|
| 11 |
+
Restaurant Scout
|
| 12 |
+
goal: >
|
| 13 |
+
Find highly-rated restaurants and dining experiences including off-the-beat options at the destination, and recommend scenic locations and fun activities
|
| 14 |
+
backstory: >
|
| 15 |
+
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.
|
| 16 |
+
|
| 17 |
+
itinerary_compiler:
|
| 18 |
+
role: >
|
| 19 |
+
Itinerary Compiler
|
| 20 |
+
goal: >
|
| 21 |
+
Compile all researched information into a comprehensive day-by-day itinerary, ensuring the integration of flights and hotel information
|
| 22 |
+
backstory: >
|
| 23 |
+
With an eye for detail, you organize all the information into a coherent and enjoyable travel plan.
|
config/tasks.yaml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
personalized_activity_planning_task:
|
| 2 |
+
description: >
|
| 3 |
+
Research and find cool things to do at {destination}.
|
| 4 |
+
Focus on activities and events that match the traveler's interests and age group.
|
| 5 |
+
Utilize internet search tools and recommendation engines to gather the information.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Traveler's information:
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
- origin: {origin}
|
| 12 |
+
|
| 13 |
+
- destination: {destination}
|
| 14 |
+
|
| 15 |
+
- age of the traveler: {age}
|
| 16 |
+
|
| 17 |
+
- how long is the trip: {trip_duration}
|
| 18 |
+
expected_output: >
|
| 19 |
+
A list of recommended activities and events for each day of the trip.
|
| 20 |
+
Each entry should include the activity name, location, a brief description, and why it's suitable for the traveler.
|
| 21 |
+
And potential reviews and ratings of the activities.
|
| 22 |
+
|
| 23 |
+
restaurant_scenic_location_scout_task:
|
| 24 |
+
description: >
|
| 25 |
+
Find highly-rated restaurants and dining experiences at {destination}.
|
| 26 |
+
Recommend scenic locations and fun activities that align with the traveler's preferences.
|
| 27 |
+
Use internet search tools, restaurant review sites, and travel guides.
|
| 28 |
+
Make sure to find a variety of options to suit different tastes and budgets, and ratings for them.
|
| 29 |
+
|
| 30 |
+
Traveler's information:
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
- origin: {origin}
|
| 34 |
+
|
| 35 |
+
- destination: {destination}
|
| 36 |
+
|
| 37 |
+
- age of the traveler: {age}
|
| 38 |
+
|
| 39 |
+
- how long is the trip: {trip_duration}
|
| 40 |
+
expected_output: >
|
| 41 |
+
A list of recommended restaurants, scenic locations, and fun activities for each day of the trip.
|
| 42 |
+
Each entry should include the name, location (address), type of cuisine or activity, and a brief description and ratings.
|
| 43 |
+
|
| 44 |
+
itinerary_compilation_task:
|
| 45 |
+
description: >
|
| 46 |
+
Compile all researched information into a comprehensive day-by-day itinerary for the trip to {destination}.
|
| 47 |
+
Ensure the itinerary integrates flights, hotel information, and all planned activities and dining experiences.
|
| 48 |
+
Use text formatting and document creation tools to organize the information.
|
| 49 |
+
expected_output: >
|
| 50 |
+
A detailed itinerary document, the itinerary should include a day-by-day
|
| 51 |
+
plan with activities, restaurants, and scenic locations. 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.
|
crew.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai import Agent, Crew, Process, Task, LLM
|
| 2 |
+
from crewai.project import CrewBase, agent, crew, task
|
| 3 |
+
|
| 4 |
+
# Uncomment the following line to use an example of a custom tool
|
| 5 |
+
# from surprise_travel.tools.custom_tool import MyCustomTool
|
| 6 |
+
|
| 7 |
+
# Check our tools documentation for more information on how to use them
|
| 8 |
+
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
|
| 9 |
+
#from pydantic import BaseModel, Field
|
| 10 |
+
from typing import List, Optional
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
os.environ["OPENAI_API_KEY"] = "aGlhbWl0YWJoYV9fZ21haWwuY29tOnhvbnhGMmh2MEU="
|
| 14 |
+
os.environ["OPENAI_API_BASE"] = "https://api.sambanova.ai/v1"
|
| 15 |
+
os.environ["OPENAI_MODEL_NAME"] = "sambanova/Meta-Llama-3.1-70B-Instruct"
|
| 16 |
+
|
| 17 |
+
llm = LLM(model="sambanova/Meta-Llama-3.1-70B-Instruct")
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
class Activity(BaseModel):
|
| 21 |
+
name: str = Field(..., description="Name of the activity")
|
| 22 |
+
location: str = Field(..., description="Location of the activity")
|
| 23 |
+
description: str = Field(..., description="Description of the activity")
|
| 24 |
+
date: str = Field(..., description="Date of the activity")
|
| 25 |
+
cousine: str = Field(..., description="Cousine of the restaurant")
|
| 26 |
+
why_its_suitable: str = Field(..., description="Why it's suitable for the traveler")
|
| 27 |
+
reviews: Optional[List[str]] = Field(..., description="List of reviews")
|
| 28 |
+
rating: Optional[float] = Field(..., description="Rating of the activity")
|
| 29 |
+
|
| 30 |
+
class DayPlan(BaseModel):
|
| 31 |
+
date: str = Field(..., description="Date of the day")
|
| 32 |
+
activities: List[Activity] = Field(..., description="List of activities")
|
| 33 |
+
restaurants: List[str] = Field(..., description="List of restaurants")
|
| 34 |
+
flight: Optional[str] = Field(None, description="Flight information")
|
| 35 |
+
|
| 36 |
+
class Itinerary(BaseModel):
|
| 37 |
+
name: str = Field(..., description="Name of the itinerary, something funny")
|
| 38 |
+
day_plans: List[DayPlan] = Field(..., description="List of day plans")
|
| 39 |
+
hotel: str = Field(..., description="Hotel information")
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
@CrewBase
|
| 43 |
+
class SurpriseTravelCrew():
|
| 44 |
+
"""SurpriseTravel crew"""
|
| 45 |
+
agents_config = 'config/agents.yaml'
|
| 46 |
+
tasks_config = 'config/tasks.yaml'
|
| 47 |
+
|
| 48 |
+
@agent
|
| 49 |
+
def personalized_activity_planner(self) -> Agent:
|
| 50 |
+
return Agent(
|
| 51 |
+
config=self.agents_config['personalized_activity_planner'],
|
| 52 |
+
llm=llm,
|
| 53 |
+
max_iter=1,
|
| 54 |
+
tools=[SerperDevTool(), ScrapeWebsiteTool()], # Example of custom tool, loaded at the beginning of file
|
| 55 |
+
verbose=True,
|
| 56 |
+
allow_delegation=False,
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
@agent
|
| 60 |
+
def restaurant_scout(self) -> Agent:
|
| 61 |
+
return Agent(
|
| 62 |
+
config=self.agents_config['restaurant_scout'],
|
| 63 |
+
llm=llm,
|
| 64 |
+
max_iter=1,
|
| 65 |
+
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
| 66 |
+
verbose=True,
|
| 67 |
+
allow_delegation=False,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
@agent
|
| 71 |
+
def itinerary_compiler(self) -> Agent:
|
| 72 |
+
return Agent(
|
| 73 |
+
config=self.agents_config['itinerary_compiler'],
|
| 74 |
+
llm=llm,
|
| 75 |
+
max_iter=1,
|
| 76 |
+
tools=[SerperDevTool()],
|
| 77 |
+
verbose=True,
|
| 78 |
+
allow_delegation=False,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
@task
|
| 82 |
+
def personalized_activity_planning_task(self) -> Task:
|
| 83 |
+
return Task(
|
| 84 |
+
config=self.tasks_config['personalized_activity_planning_task'],
|
| 85 |
+
llm=llm,
|
| 86 |
+
max_iter=1,
|
| 87 |
+
agent=self.personalized_activity_planner()
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
@task
|
| 91 |
+
def restaurant_scenic_location_scout_task(self) -> Task:
|
| 92 |
+
return Task(
|
| 93 |
+
config=self.tasks_config['restaurant_scenic_location_scout_task'],
|
| 94 |
+
llm=llm,
|
| 95 |
+
max_iter=1,
|
| 96 |
+
agent=self.restaurant_scout()
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
@task
|
| 100 |
+
def itinerary_compilation_task(self) -> Task:
|
| 101 |
+
return Task(
|
| 102 |
+
config=self.tasks_config['itinerary_compilation_task'],
|
| 103 |
+
llm=llm,
|
| 104 |
+
max_iter=1,
|
| 105 |
+
agent=self.itinerary_compiler(),
|
| 106 |
+
# output_json=Itinerary
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
@crew
|
| 110 |
+
def crew(self) -> Crew:
|
| 111 |
+
"""Creates the SurpriseTravel crew"""
|
| 112 |
+
return Crew(
|
| 113 |
+
agents=self.agents, # Automatically created by the @agent decorator
|
| 114 |
+
tasks=self.tasks, # Automatically created by the @task decorator
|
| 115 |
+
process=Process.sequential,
|
| 116 |
+
verbose=True,
|
| 117 |
+
# process=Process.hierarchical, # In case you want to use that instead https://docs.crewai.com/how-to/Hierarchical/
|
| 118 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
crewai
|
| 2 |
+
crewai-tools
|