-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtravel_app2.py
More file actions
76 lines (60 loc) · 3.56 KB
/
Copy pathtravel_app2.py
File metadata and controls
76 lines (60 loc) · 3.56 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
import json
import os
import google.generativeai as genai
# Use the API key from the environment variable
api_key = os.environ.get("AI_API_KEY")
genai.configure(api_key=api_key)
def load_travel_data(filename):
"""Load travel data from a JSON file"""
with open(filename, 'r') as file:
data = json.load(file)
return data
def generate_travel_plan(schedule, flights, hotels, departure, destination, travel_dates, interests,budget,attractions):
"""Generate a travel plan based on the weekly schedule, flights, hotels, and user input"""
model = genai.GenerativeModel(model_name="gemini-1.5-flash")
chat_session = model.start_chat(history=[])
# Create a prompt based on the user input and travel options
message = f"""
I need help planning my travel from {departure} to {destination} on the following dates: {travel_dates}.
Book the activities and flight so it doesnt interfere with the {schedule}
My interests include: {interests}.
Can you book my flights in such a way that they don't interfere with my schedule and return the adequate link so I can book it?
Here are the available flights:
{flights}.
And here are the hotel options:
{hotels}.
there are the attractions in the cities: {attractions}
Please suggest the best flight and hotel combination based on my schedule and interests.
My budget is {budget}, and I want to make sure to arrive in time for important meetings and commitments. Can you give me the itenary in
the following fomat: Day 1 >12:00PM:..... Day 2... Make it very elaborate per day so its easy to plan for the user. book slot for user to go to attraction in the city.
end the itenary once the person is on the flight back to the original city. Dont use "afternoon, moring, evening", use time slots for everything. Specify which bus need to be taken to get around the city.
Can you also add the link for flight and hotel booking from the flight and hotel options. The flights run on a periodic basis. Choose the correct {hotels} that fit the budget
Make sure same input response should always give the same output.
Do not include {schedule} in the iternanry but make the plans around it.
Do not include {schedule} in the iternanry but make the plans around it.
Make sure the total cost of the entire trip with the attraction is less than {budget}
Also provide price summary and breakdwon.
"""
response = chat_session.send_message(message)
return response.text
def main():
# Load travel data from the JSON file
travel_data = load_travel_data('C:/Users/aadya/OneDrive/Desktop/davinci/travel_db.json')
# Extract flights, hotels, and schedule
flights = travel_data["flights"]
hotels = travel_data["hotels"]
schedule = travel_data["weekly_schedule"]
attractions = travel_data["attractions"]
# Get user input for travel details
departure = input("Enter your departure location: ")
destination = input("Enter your destination location: ")
travel_dates = input("Enter your travel dates (e.g., 'October 1-10, 2024'): ")
interests = input("Enter your interests (eg: 'sightseeing, food, culture'): ")
budget=input("Enter your budget for the entire trip (In USD) :$")
# Generate a travel plan using the schedule, flights, hotels, and user input
travel_plan = generate_travel_plan(schedule, flights, hotels, departure, destination, travel_dates, interests,budget,attractions)
# Output the generated travel plan
print(f"\n--- Travel Plan ---\n")
print(travel_plan)
if __name__ == "__main__":
main()