Upload 3 files
Browse files- .gitignore +11 -0
- app.py +208 -0
- requirement.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore virtual environments
|
| 2 |
+
myenv/
|
| 3 |
+
|
| 4 |
+
# Ignore the folder
|
| 5 |
+
Traven-Itinerary-Project/
|
| 6 |
+
|
| 7 |
+
# Ignore .env
|
| 8 |
+
.env
|
| 9 |
+
|
| 10 |
+
# Ignore .devcontainer
|
| 11 |
+
.devcontainer
|
app.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from langchain_groq import ChatGroq
|
| 5 |
+
from langchain_core.messages import HumanMessage, SystemMessage
|
| 6 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
+
|
| 12 |
+
# Validate API Key
|
| 13 |
+
if not GROQ_API_KEY:
|
| 14 |
+
raise ValueError("GROQ_API_KEY environment variable is not set")
|
| 15 |
+
|
| 16 |
+
# Function to fetch Wikipedia summary
|
| 17 |
+
def search_travel_info(destination):
|
| 18 |
+
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{destination}"
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
if response.status_code == 200:
|
| 21 |
+
data = response.json()
|
| 22 |
+
return data.get("extract", "No information found.")
|
| 23 |
+
return "No results found."
|
| 24 |
+
|
| 25 |
+
# Function to generate travel itinerary using Groq API
|
| 26 |
+
def generate_itinerary(start_location, budget, duration, destination, purpose, preferences):
|
| 27 |
+
search_results = search_travel_info(destination)
|
| 28 |
+
|
| 29 |
+
# Create prompt template
|
| 30 |
+
prompt_template = ChatPromptTemplate.from_messages([
|
| 31 |
+
SystemMessage(content="You are an expert travel guide. Provide a detailed travel itinerary."),
|
| 32 |
+
HumanMessage(content=f"""
|
| 33 |
+
Create a {duration}-day travel itinerary for a traveler going from {start_location} to {destination}.
|
| 34 |
+
|
| 35 |
+
### π·οΈ Traveler Information:
|
| 36 |
+
- Budget: {budget}
|
| 37 |
+
- Purpose of Travel: {purpose}
|
| 38 |
+
- Preferences: {preferences}
|
| 39 |
+
|
| 40 |
+
### π Day-wise Itinerary:
|
| 41 |
+
- π Activities (morning, afternoon, evening)
|
| 42 |
+
- π Attractions (landmarks & hidden gems)
|
| 43 |
+
- π½οΈ Food recommendations
|
| 44 |
+
- π¨ Accommodation options
|
| 45 |
+
- π Transportation details
|
| 46 |
+
|
| 47 |
+
### π Additional Travel Info:
|
| 48 |
+
{search_results}
|
| 49 |
+
""")
|
| 50 |
+
])
|
| 51 |
+
|
| 52 |
+
# Initialize Groq Chat Model (Llama3-8B)
|
| 53 |
+
llm = ChatGroq(temperature=0,model_name="llama-3.3-70b-versatile", api_key=GROQ_API_KEY)
|
| 54 |
+
|
| 55 |
+
# Generate response
|
| 56 |
+
response = llm.invoke(prompt_template.format())
|
| 57 |
+
|
| 58 |
+
return response.content if response else "Error: Unable to generate itinerary."
|
| 59 |
+
|
| 60 |
+
# Set page config (add this at the very top)
|
| 61 |
+
st.set_page_config(page_title="AI Travel Planner", page_icon="βοΈ")
|
| 62 |
+
|
| 63 |
+
# Apply global background image
|
| 64 |
+
st.markdown(
|
| 65 |
+
"""
|
| 66 |
+
<style>
|
| 67 |
+
.stApp {
|
| 68 |
+
# background-image: url("https://images.unsplash.com/photo-1436491865332-7a61a109cc05");
|
| 69 |
+
# background-image: url("https://images.unsplash.com/photo-1506748686214-e9df14d4d9d0");
|
| 70 |
+
background-image: url("https://images.unsplash.com/photo-1483728642387-6c3bdd6c93e5");
|
| 71 |
+
# 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");
|
| 72 |
+
background-size: cover;
|
| 73 |
+
background-position: center;
|
| 74 |
+
background-attachment: fixed;
|
| 75 |
+
filter: brightness(90%);
|
| 76 |
+
}
|
| 77 |
+
.stApp::before {
|
| 78 |
+
content: "";
|
| 79 |
+
position: absolute;
|
| 80 |
+
top: 0;
|
| 81 |
+
left: 0;
|
| 82 |
+
right: 0;
|
| 83 |
+
bottom: 0;
|
| 84 |
+
background: rgba(0, 0, 0, 0.4); /* 40% opaque black */
|
| 85 |
+
z-index: -1;
|
| 86 |
+
}
|
| 87 |
+
.form-title {
|
| 88 |
+
color: white !important;
|
| 89 |
+
font-size: 2rem;
|
| 90 |
+
font-weight: bold;
|
| 91 |
+
text-align: center;
|
| 92 |
+
}
|
| 93 |
+
.form-subtitle {
|
| 94 |
+
color: white !important;
|
| 95 |
+
font-size: 1.2rem;
|
| 96 |
+
text-align: center;
|
| 97 |
+
margin-bottom: 1.5rem;
|
| 98 |
+
}
|
| 99 |
+
/* Frosted Glass Box */
|
| 100 |
+
.frosted-glass-box {
|
| 101 |
+
background: rgba(255, 255, 255, 0.2);
|
| 102 |
+
backdrop-filter: blur(10px);
|
| 103 |
+
-webkit-backdrop-filter: blur(10px);
|
| 104 |
+
border-radius: 15px;
|
| 105 |
+
padding: 2rem;
|
| 106 |
+
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.2);
|
| 107 |
+
width: 80%;
|
| 108 |
+
margin: auto;
|
| 109 |
+
}
|
| 110 |
+
/* Input Styling */
|
| 111 |
+
.stTextInput input,
|
| 112 |
+
.stSelectbox select,
|
| 113 |
+
.stNumberInput input,
|
| 114 |
+
.stTextArea textarea {
|
| 115 |
+
color: #000000 !important;
|
| 116 |
+
background-color: rgba(255, 255, 255, 0.7) !important;
|
| 117 |
+
border-radius: 8px !important;
|
| 118 |
+
border: 1px solid rgba(0, 0, 0, 0.1) !important;
|
| 119 |
+
padding: 10px;
|
| 120 |
+
font-size: 1rem;
|
| 121 |
+
}
|
| 122 |
+
/* Button Styling */
|
| 123 |
+
.stButton button {
|
| 124 |
+
background-color: black !important;
|
| 125 |
+
color: white !important;
|
| 126 |
+
border-radius: 8px !important;
|
| 127 |
+
padding: 10px 20px !important;
|
| 128 |
+
font-size: 1rem;
|
| 129 |
+
font-weight: bold !important;
|
| 130 |
+
width: 100% !important;
|
| 131 |
+
margin-top: 1rem !important;
|
| 132 |
+
border: none !important;
|
| 133 |
+
}
|
| 134 |
+
.stButton button:hover {
|
| 135 |
+
background-color: white !important;
|
| 136 |
+
color: black !important;
|
| 137 |
+
border: 1.5px solid black !important;
|
| 138 |
+
}
|
| 139 |
+
/* Itinerary Box */
|
| 140 |
+
.itinerary-box {
|
| 141 |
+
background: rgba(255, 255, 255, 0.7);
|
| 142 |
+
border-radius: 15px;
|
| 143 |
+
padding: 1.5rem;
|
| 144 |
+
margin-top: 1.5rem;
|
| 145 |
+
width: 80%;
|
| 146 |
+
margin: auto;
|
| 147 |
+
}
|
| 148 |
+
</style>
|
| 149 |
+
""",
|
| 150 |
+
unsafe_allow_html=True
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
# Start of the frosted glass box
|
| 154 |
+
# st.markdown('<div class="frosted-glass-box">', unsafe_allow_html=True)
|
| 155 |
+
|
| 156 |
+
# Title and Subtitle
|
| 157 |
+
st.markdown('<h1 class="form-title">AI-Powered Travel Planner βοΈ</h1>', unsafe_allow_html=True)
|
| 158 |
+
st.markdown('<p class="form-subtitle">Plan your next trip with AI!</p>', unsafe_allow_html=True)
|
| 159 |
+
|
| 160 |
+
# Form Elements (Columns for Structure)
|
| 161 |
+
col1, col2 = st.columns(2)
|
| 162 |
+
with col1:
|
| 163 |
+
start_location = st.text_input("π Starting Location")
|
| 164 |
+
with col2:
|
| 165 |
+
destination = st.text_input("π Destination")
|
| 166 |
+
|
| 167 |
+
col3, col4 = st.columns(2)
|
| 168 |
+
with col3:
|
| 169 |
+
budget = st.selectbox("π° Select Budget", ["Low", "Moderate", "Luxury"])
|
| 170 |
+
with col4:
|
| 171 |
+
duration = st.number_input("π
Trip Duration (days)", min_value=1, max_value=30, value=3)
|
| 172 |
+
|
| 173 |
+
# Full-width Form Elements
|
| 174 |
+
purpose = st.text_area("π Purpose of Trip")
|
| 175 |
+
preferences = st.text_area("π― Your Preferences (e.g., adventure, food, history)")
|
| 176 |
+
|
| 177 |
+
# Close the frosted glass div
|
| 178 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 179 |
+
|
| 180 |
+
# # Button and Itinerary Box
|
| 181 |
+
# if st.button("π Generate Itinerary"):
|
| 182 |
+
# if start_location and destination and purpose and preferences:
|
| 183 |
+
# itinerary = f"Here is a sample itinerary for {start_location} to {destination}."
|
| 184 |
+
# st.markdown('<div class="itinerary-box">', unsafe_allow_html=True)
|
| 185 |
+
# st.subheader("π Your AI-Generated Itinerary:")
|
| 186 |
+
# st.write(itinerary)
|
| 187 |
+
# st.markdown('</div>', unsafe_allow_html=True)
|
| 188 |
+
# else:
|
| 189 |
+
# st.warning("β οΈ Please fill in all fields.")
|
| 190 |
+
|
| 191 |
+
# # Streamlit UI
|
| 192 |
+
# st.title("AI-Powered Travel Planner π§³")
|
| 193 |
+
# st.write("Plan your next trip with AI!")
|
| 194 |
+
|
| 195 |
+
# start_location = st.text_input("Starting Location")
|
| 196 |
+
# destination = st.text_input("Destination")
|
| 197 |
+
# budget = st.selectbox("Select Budget", ["Low", "Moderate", "Luxury"])
|
| 198 |
+
# duration = st.number_input("Trip Duration (days)", min_value=1, max_value=30, value=3)
|
| 199 |
+
# purpose = st.text_area("Purpose of Trip")
|
| 200 |
+
# preferences = st.text_area("Your Preferences (e.g., adventure, food, history)")
|
| 201 |
+
|
| 202 |
+
if st.button("Generate Itinerary"):
|
| 203 |
+
if start_location and destination and purpose and preferences:
|
| 204 |
+
itinerary = generate_itinerary(start_location, budget, duration, destination, purpose, preferences)
|
| 205 |
+
st.subheader("Your AI-Generated Itinerary:")
|
| 206 |
+
st.write(itinerary)
|
| 207 |
+
else:
|
| 208 |
+
st.warning("Please fill in all fields.")
|
requirement.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
| 3 |
+
langchain
|
| 4 |
+
langchain-groq==0.1.3
|