Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,53 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import streamlit as st
|
| 3 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
-
from langchain.schema import SystemMessage, HumanMessage
|
| 5 |
-
from langchain.chains import LLMChain
|
| 6 |
-
from langchain.prompts import PromptTemplate
|
| 7 |
-
from dotenv import load_dotenv
|
| 8 |
-
|
| 9 |
-
# Load environment variables
|
| 10 |
-
load_dotenv()
|
| 11 |
-
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 12 |
-
|
| 13 |
-
# Initialize AI Model
|
| 14 |
-
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", google_api_key=GOOGLE_API_KEY)
|
| 15 |
-
|
| 16 |
-
# Define a Prompt Template
|
| 17 |
-
prompt = PromptTemplate(
|
| 18 |
-
input_variables=["source", "destination"],
|
| 19 |
-
template="""
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
+
from langchain.schema import SystemMessage, HumanMessage
|
| 5 |
+
from langchain.chains import LLMChain
|
| 6 |
+
from langchain.prompts import PromptTemplate
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 12 |
+
|
| 13 |
+
# Initialize AI Model
|
| 14 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", google_api_key=GOOGLE_API_KEY)
|
| 15 |
+
|
| 16 |
+
# Define a Prompt Template
|
| 17 |
+
prompt = PromptTemplate(
|
| 18 |
+
input_variables=["source", "destination"],
|
| 19 |
+
template="""
|
| 20 |
+
You are an AI-powered travel planner.
|
| 21 |
+
|
| 22 |
+
Plan a detailed {}-day budget trip from {source} to {destination}.
|
| 23 |
+
|
| 24 |
+
Include:
|
| 25 |
+
1. **Travel Options** — cab, train, bus, and flight with estimated one-way and roundtrip costs.
|
| 26 |
+
2. **Stay Options** — budget, mid-range, and premium stays with approximate cost per night.
|
| 27 |
+
3. **Local Transport** — average cost per day for autos, e-rickshaws, or cabs.
|
| 28 |
+
4. **Food & Drinks** — per-day budget for local meals.
|
| 29 |
+
5. **Extra Costs** — sightseeing entry, boat rides, shopping, etc.
|
| 30 |
+
6. **Total Estimated Cost** — show total for 4 days (low-budget and mid-range).
|
| 31 |
+
7. **Sample Itinerary (Day-wise)** — brief plan for 4 days.
|
| 32 |
+
|
| 33 |
+
Format the response clearly using markdown (### headings and bullet points).
|
| 34 |
+
"""
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Streamlit UI
|
| 38 |
+
st.title("AI-Powered Travel Planner")
|
| 39 |
+
source = st.text_input("Enter Source:")
|
| 40 |
+
destination = st.text_input("Enter Destination:")
|
| 41 |
+
|
| 42 |
+
if st.button("Find Travel Options"):
|
| 43 |
+
if source and destination:
|
| 44 |
+
messages = [
|
| 45 |
+
SystemMessage(content="You are an AI travel assistant."),
|
| 46 |
+
HumanMessage(content=prompt.format(source=source, destination=destination))
|
| 47 |
+
]
|
| 48 |
+
response = llm(messages)
|
| 49 |
+
st.write("### Travel Recommendations:")
|
| 50 |
+
st.markdown(response.content)
|
| 51 |
+
else:
|
| 52 |
+
st.warning("Please enter both source and destination.")
|
| 53 |
+
|