-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtravel-agent-app.py
More file actions
102 lines (84 loc) · 2.69 KB
/
Copy pathtravel-agent-app.py
File metadata and controls
102 lines (84 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langchain.agents import create_openai_tools_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.tools import DuckDuckGoSearchRun
import os
from dotenv import load_dotenv
load_dotenv()
# ----------------------------
# Streamlit Page Config
# ----------------------------
st.set_page_config(page_title="AI Travel Planner", layout="wide")
st.title("🌍 Agentic AI Holiday Planner")
# ----------------------------
# LLM
# ----------------------------
llm = ChatOpenAI(
model="gpt-4.1",
temperature=0.4
)
# ----------------------------
# Tools
# ----------------------------
@tool
def budget_estimator(days: int, total_budget: int) -> str:
"""Estimate daily budget split."""
per_day = total_budget / days
return f"Recommended daily budget: ₹{round(per_day)}"
@tool
def weather_lookup(city: str) -> str:
"""Mock weather info."""
return f"{city} usually has pleasant travel weather this season."
search_tool = DuckDuckGoSearchRun()
tools = [budget_estimator, weather_lookup, search_tool]
# ----------------------------
# Prompt
# ----------------------------
prompt = ChatPromptTemplate.from_messages([
("system", """
You are an expert AI travel planner.
You must:
- Research destination
- Suggest day-by-day itinerary
- Recommend hotels and food
- Estimate budget breakdown
- Consider weather
- Provide travel tips
- Output clean structured format
"""),
("human", "{input}"),
("placeholder", "{agent_scratchpad}")
])
agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=False
)
# ----------------------------
# UI Inputs
# ----------------------------
col1, col2 = st.columns(2)
with col1:
destination = st.text_input("Destination", "Bali")
days = st.number_input("Number of Days", min_value=1, max_value=15, value=5)
budget = st.number_input("Total Budget (₹)", min_value=10000, value=150000)
with col2:
travelers = st.selectbox("Travel Type", ["Family", "Couple", "Solo", "Friends"])
preferences = st.text_area("Preferences",
"Beaches, temples, kid-friendly activities")
# ----------------------------
# Run Agent
# ----------------------------
if st.button("Plan My Trip ✈️"):
user_query = f"""
Plan a {days}-day {travelers} holiday trip to {destination}.
Total budget ₹{budget}.
Preferences: {preferences}.
"""
with st.spinner("Planning your trip..."):
result = executor.invoke({"input": user_query})
st.subheader("🗺️ Your Travel Plan")
st.write(result["output"])