Trip_Planner / app.py
YAMITEK's picture
Update app.py
6cf9388 verified
import streamlit as st
import os
from crewai import Agent, Task, Crew, Process, LLM
from crewai_tools import SerperDevTool
gemini_key=os.getenv("GOOGLE_API_KEY")
serper_key=os.getenv("SERPER_API_KEY")
# Initialize a search tool (to fetch real-time travel info)
search_tool = SerperDevTool()
st.title("Trip Planner")
# Define the AI Model
llm = LLM(model="gemini/gemini-1.5-flash",
verbose=True,
temperature=0.5,
api_key=gemini_key)#os.environ["GOOGLE_API_KEY"]
# 🧭 Travel Researcher Agent (Finds historical sites + weather)
researcher = Agent(
role="Travel Researcher",
goal="Find {places_type} of places , public transport hotels, and real-time weather for {destination} from {starting} based on {type}.",
verbose=True,
memory=True,
backstory="You are an expert travel researcher, providing up-to-date information about history-focused trips.",
llm=llm,
tools=[search_tool], # Uses live search tool
allow_delegation=True
)
# πŸ’° Budget Planner Agent (Ensures trip stays under $1500)
budget_planner = Agent(
role="Budget Planner",
goal="Find budget flights, hotels, and activities within {budget} for {destination} from {starting},with in the dates from date {staring_date} to {ending_date}.",
verbose=True,
memory=True,
backstory="You are a skilled budget analyst ensuring trips fit within financial constraints.",
llm=llm,
tools=[search_tool],
allow_delegation=False
)
# πŸ—ΊοΈ Itinerary Planner Agent (Creates a balanced 3-day plan)
itinerary_planner = Agent(
role="Itinerary Planner",
goal="Create a itinerary for {destination} from {starting}, ensuring all historical sites are covered under {budget} based on {type}.",
verbose=True,
memory=True,
backstory="You are an expert in trip planning, ensuring travelers get the best experience within their budget.",
llm=llm,
tools=[search_tool],
allow_delegation=False
)
# πŸ“ Travel Research Task
research_task = Task(
description="Find the best historical sites, weather forecast, and public transport hotels for {destination}.",
expected_output="A list of top historical sites, a real-time weather update, and 3 hotel options near public transport.",
tools=[search_tool],
agent=researcher
)
# πŸ’² Budget Estimation Task
budget_task = Task(
description="Find budget flights, hotel options, and daily food/transport costs for {destination} based on from date {staring_date} to {ending_date}. Ensure total cost stays under {budget}.",
expected_output="A full cost breakdown (flights, hotel, food, attractions) ensuring a {budget} budget is maintained.",
tools=[search_tool],
agent=budget_planner
)
# πŸ“… Itinerary Planning Task
itinerary_task = Task(
description="Plan a from date {staring_date} to {ending_date} itinerary for {destination}, focusing on historical sites, budget constraints, and real-time weather conditions.",
expected_output="A detailed 3-day plan, considering weather and budget constraints, with transport recommendations.",
tools=[search_tool],
agent=itinerary_planner
)
# πŸš€ Crew Setup: All agents working together!
crew = Crew(
agents=[researcher, budget_planner, itinerary_planner],
tasks=[research_task, budget_task, itinerary_task],
process=Process.sequential # Runs tasks in sequence
)
col1,col2=st.columns(2)
with col1:
start=st.text_input("Enter the starting Place")
with col2:
destination=st.text_input("Enter the destinataion Place")
col1,col2 =st.columns(2)
with col1:
staring_date = st.date_input("pick start date of trip")
with col2:
ending_date =st.date_input("pick ending date of trip")
col1,col2=st.columns(2)
with col1:
type_option=[ "Business / Luxury "," Economics/Budget Friendly","cheaper "]
type=st.selectbox("select the type of Experience ",options=type_option)
with col2:
budget=st.number_input("Enter the Budget in Rupees",step=100)
places= st.text_input("Enter the places Your are intersted to vist (Please separe the places with colums ',')")
places_type=places.split(",")
if st.button("submit "):
result = crew.kickoff(inputs={"starting":start,'destination':destination ,"type":type,"places_type":places_type,
'budget': budget,"staring_date":str(staring_date) ,"ending_date":str(ending_date)})
st.write(result.raw)