File size: 6,298 Bytes
1ee439e
 
 
 
 
 
 
d35f788
1ee439e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393c318
df22110
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import streamlit as st
import requests
import os
os.system("pip install langchain-groq==0.1.3")
from langchain_groq import ChatGroq
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.prompts import ChatPromptTemplate
os.system("pip install python-dotenv")
from dotenv import load_dotenv

load_dotenv()  
GROQ_API_KEY = os.getenv("GROQ_API_KEY") 

# Validate API Key
if not GROQ_API_KEY:
    raise ValueError("GROQ_API_KEY environment variable is not set")

# Function to fetch Wikipedia summary
def search_travel_info(destination):
    url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{destination}"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        return data.get("extract", "No information found.")
    return "No results found."

# Function to generate travel itinerary using Groq API
def generate_itinerary(start_location, budget, duration, destination, purpose, preferences):
    search_results = search_travel_info(destination)
    
    # Create prompt template
    prompt_template = ChatPromptTemplate.from_messages([
        SystemMessage(content="You are an expert travel guide. Provide a detailed travel itinerary."),
        HumanMessage(content=f"""
            Create a {duration}-day travel itinerary for a traveler going from {start_location} to {destination}.
            
            ### 🏷️ Traveler Information:
            - Budget: {budget}
            - Purpose of Travel: {purpose}
            - Preferences: {preferences}
            
            ### πŸš† Day-wise Itinerary:
            - πŸ“ Activities (morning, afternoon, evening)
            - 🎭 Attractions (landmarks & hidden gems)
            - 🍽️ Food recommendations
            - 🏨 Accommodation options
            - πŸš— Transportation details
            
            ### πŸ“Œ Additional Travel Info:
            {search_results}
        """)
    ])
    
    # Initialize Groq Chat Model (Llama3-8B)
    llm = ChatGroq(temperature=0,model_name="llama-3.3-70b-versatile", api_key=GROQ_API_KEY)
    
    # Generate response
    response = llm.invoke(prompt_template.format())
    
    return response.content if response else "Error: Unable to generate itinerary."

# Set page config (add this at the very top)
st.set_page_config(page_title="AI Travel Planner", page_icon="✈️")

# Apply global background image
st.markdown(
    """
    <style>
    .stApp {
        # background-image: url("https://images.unsplash.com/photo-1436491865332-7a61a109cc05");
        # background-image: url("https://images.unsplash.com/photo-1506748686214-e9df14d4d9d0");
        background-image: url("https://images.unsplash.com/photo-1483728642387-6c3bdd6c93e5");
        # background-image: url("https://images.unsplash.com/photo-1518563259479-d003c05a6507?q=80&w=1470&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D");
        background-size: cover;
        background-position: center;
        background-attachment: fixed;
        filter: brightness(90%);
    }
    .stApp::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);  /* 40% opaque black */
        z-index: -1;
    }
    .form-title {
        color: white !important;
        font-size: 2rem;
        font-weight: bold;
        text-align: center;
    }
    .form-subtitle {
        color: white !important;
        font-size: 1.2rem;
        text-align: center;
        margin-bottom: 1.5rem;
    }
    /* Frosted Glass Box */
    .frosted-glass-box {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 15px;
        padding: 2rem;
        box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.2);
        width: 80%;
        margin: auto;
    }
    /* Input Styling */
    .stTextInput input, 
    .stSelectbox select, 
    .stNumberInput input, 
    .stTextArea textarea {
        color: #000000 !important;
        background-color: rgba(255, 255, 255, 0.7) !important;
        border-radius: 8px !important;
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
        padding: 10px;
        font-size: 1rem;
    }
    /* Button Styling */
    .stButton button {
        background-color: black !important;
        color: white !important;
        border-radius: 8px !important;
        padding: 10px 20px !important;
        font-size: 1rem;
        font-weight: bold !important;
        width: 100% !important;
        margin-top: 1rem !important;
        border: none !important;
    }
    .stButton button:hover {
        background-color: white !important;
        color: black !important;
        border: 1.5px solid black !important;
    }
    /* Itinerary Box */
    .itinerary-box {
        background: rgba(255, 255, 255, 0.7);
        border-radius: 15px;
        padding: 1.5rem;
        margin-top: 1.5rem;
        width: 80%;
        margin: auto;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Title and Subtitle
st.markdown('<h1 class="form-title">AI-Powered Travel Planner ✈️</h1>', unsafe_allow_html=True)
st.markdown('<p class="form-subtitle">Plan your next trip with AI!</p>', unsafe_allow_html=True)

# Form Elements (Columns for Structure)
col1, col2 = st.columns(2)
with col1:
    start_location = st.text_input("πŸ“ Starting Location")
with col2:
    destination = st.text_input("🌍 Destination")

col3, col4 = st.columns(2)
with col3:
    budget = st.selectbox("πŸ’° Select Budget", ["Low", "Moderate", "Luxury"])
with col4:
    duration = st.number_input("πŸ“… Trip Duration (days)", min_value=1, max_value=30, value=3)

# Full-width Form Elements
purpose = st.text_area("πŸ“ Purpose of Trip")
preferences = st.text_area("🎯 Your Preferences (e.g., adventure, food, history)")

if st.button("Generate Itinerary"):
    if start_location and destination and purpose and preferences:
        itinerary = generate_itinerary(start_location, budget, duration, destination, purpose, preferences)
        st.subheader("Your AI-Generated Itinerary:")
        st.write(itinerary)
    else:
        
        st.warning("Please fill in all fields.")